1.3.3 • Published 2 years ago
mongoose-model-templates v1.3.3
Installation
Install at the server level:
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)
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
Flags
Provided your index.js file takes the following format
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
npm run create:model -name=User -x
Output:
User.js:
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:
const User = require("./User");
const Post = require("./Post");
const Comment = require("./Comment");
module.exports = {
Post,
Comment,
User,
};
1.3.3
2 years ago
1.3.2
2 years ago
1.3.1
2 years ago
1.3.0
2 years ago
1.2.1
2 years ago
1.2.0
2 years ago
1.1.11
2 years ago
1.1.10
2 years ago
1.1.9
2 years ago
1.1.8
2 years ago
1.1.7
2 years ago
1.1.6
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.47
2 years ago
1.0.46
2 years ago
1.0.45
2 years ago
1.0.43
2 years ago
1.0.41
2 years ago