# mongoose-model-templates

> generates template files for mongoose models

Latest version **1.3.3** (published 2022-10-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongoose-model-templates
pnpm add mongoose-model-templates
yarn add mongoose-model-templates
bun add mongoose-model-templates
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2022-10-29 |
| First published | 2022-07-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | laurawalters1 |
| Maintainers | laurawalters1 |
| Keywords | mongoose, mern, model, template, generator, command |

## Links

- npm: https://www.npmjs.com/package/mongoose-model-templates
- Repository: https://github.com/laurawalters1/mongoose-model-generator
- Homepage: https://github.com/laurawalters1/mongoose-model-templates#readme
- Issues: https://github.com/laurawalters1/mongoose-model-templates/issues
- npm.io page: https://npm.io/package/mongoose-model-templates

## Dependencies (1)

- [fs](https://npm.io/package/fs.md) ^0.0.1-security

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [@temporal-architect/claude-plugin](https://npm.io/package/@temporal-architect/claude-plugin.md) — 335 weekly downloads

## Recent versions

- 1.3.3 (latest) — 2022-10-29
- 1.3.2 — 2022-10-29
- 1.3.1 — 2022-10-29
- 1.3.0 — 2022-10-29
- 1.2.1 — 2022-07-29
- 1.2.0 — 2022-07-29
- 1.1.11 — 2022-07-13
- 1.1.10 — 2022-07-13
- 1.1.9 — 2022-07-13
- 1.1.8 — 2022-07-12
- 1.1.7 — 2022-07-12
- 1.1.6 — 2022-07-12
- 1.1.5 — 2022-07-12
- 1.1.4 — 2022-07-12
- 1.1.3 — 2022-07-12
- … 8 more at https://npm.io/package/mongoose-model-templates/versions

## README

## Installation

Install at the server level:

```javascript
npm i mongoose-model-templates
```

## Usage

Run the following command in the server directory to generate a template mongoose model (replace 'User' with your model name)

```javascript
npm run create:model -name=User
```

The file will be located in the models folder, if a models folder does not already exist, one will be created
<br>
<br>

## Flags

Provided your index.js file takes the following format

```javascript
const Post = require("./Post");
const Comment = require("./Comment");

module.exports = {
	Post,
	Comment,
};
```

You can also add the 'x' flag for model exports to be automatically added to your models/index.js, if you do not already have an index file, one will be created

```javascript
npm run create:model -name=User -x
```

## Output:

User.js:

```javascript
const { Schema, model } = require("mongoose");

const moment = require("moment");

const userSchema = new Schema(
	{
		createdAt: {
			type: Date,
			default: Date.now,
		},
	},
	{
		toJSON: {
			virtuals: true,
		},
	}
);

const User = model("User", userSchema);

module.exports = User;
```

index.js:

```javascript
const User = require("./User");
const Post = require("./Post");
const Comment = require("./Comment");

module.exports = {
	Post,
	Comment,
	User,
};
```

---
_Source: https://npm.io/package/mongoose-model-templates · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
