Gathering detailed insights and metrics for express-mongoose-gen-es6
Gathering detailed insights and metrics for express-mongoose-gen-es6
Gathering detailed insights and metrics for express-mongoose-gen-es6
Gathering detailed insights and metrics for express-mongoose-gen-es6
npm install express-mongoose-gen-es6
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
71 Commits
4 Forks
2 Watchers
1 Branches
1 Contributors
Updated on Aug 06, 2021
Latest Version
3.1.1
Package Id
express-mongoose-gen-es6@3.1.1
Size
6.94 kB
NPM Version
4.0.3
Node Version
6.9.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
It’s a mongoose model, REST controller and Express router code generator for Express.js 4 application.
1$ npm install -g express-mongoose-generator
Generates a Mongoose model, a REST controller and Express router :
1$ mongoose-gen -m car -f carDoor:number,color -r 2 create: ./models/cardModel.js 3 create: ./routes/cards.js 4 create: ./controllers/cardController.js
-m, --model <modelName>
- the model name.-f, --fields <fields>
- the fields (name1:type,name2:type).-r, --rest
- enable generation REST.Generates a Mongoose model, a REST controller and Express router :
1$ mongoose-gen 2Model Name : car 3Available types : string, number, date, boolean, array 4Field Name (press <return> to stop adding fields) : door 5Field Type [string] : number 6Field Name (press <return> to stop adding fields) : color 7Field Type [string] : 8Field Name (press <return> to stop adding fields) : owner 9Field Type [string] : objectId 10Reference (model name referred by the objectId field) : User 11Field Name (press <return> to stop adding fields) : 12Generate Rest (yes/no) ? [yes] : 13 create: ./models/carModel.js 14 create: ./routes/cars.js 15 create: ./controllers/carController.js
models/carModel.js :
1var mongoose = require('mongoose'); 2var Schema = mongoose.Schema; 3 4var carSchema = new Schema({ 5 "color" : String, 6 "door" : Number, 7 "owner" : { 8 type: Schema.Types.ObjectId, 9 ref: 'User' 10 } 11}); 12 13module.exports = mongoose.model('car', carSchema);
routes/cars.js :
1var express = require('express'); 2var router = express.Router(); 3var carController = require('../controllers/carController.js'); 4 5/* 6 * GET 7 */ 8router.get('/', function(req, res) { 9 carController.list(req, res); 10}); 11 12/* 13 * GET 14 */ 15router.get('/:id', function(req, res) { 16 carController.show(req, res); 17}); 18 19/* 20 * POST 21 */ 22router.post('/', function(req, res) { 23 carController.create(req, res); 24}); 25 26/* 27 * PUT 28 */ 29router.put('/:id', function(req, res) { 30 carController.update(req, res); 31}); 32 33/* 34 * DELETE 35 */ 36router.delete('/:id', function(req, res) { 37 carController.remove(req, res); 38}); 39 40module.exports = router;
controllers/carController.js :
1var carModel = require('../models/carModel.js'); 2 3/** 4 * carController.js 5 * 6 * @description :: Server-side logic for managing cars. 7 */ 8module.exports = { 9 10 /** 11 * carController.list() 12 */ 13 list: function(req, res) { 14 carModel.find(function(err, cars){ 15 if(err) { 16 return res.status(500).json({ 17 message: 'Error getting car.' 18 }); 19 } 20 return res.json(cars); 21 }); 22 }, 23 24 /** 25 * carController.show() 26 */ 27 show: function(req, res) { 28 var id = req.params.id; 29 carModel.findOne({_id: id}, function(err, car){ 30 if(err) { 31 return res.status(500).json({ 32 message: 'Error getting car.' 33 }); 34 } 35 if(!car) { 36 return res.status(404).json({ 37 message: 'No such car' 38 }); 39 } 40 return res.json(car); 41 }); 42 }, 43 44 /** 45 * carController.create() 46 */ 47 create: function(req, res) { 48 var car = new carModel({ 49 color : req.body.color, 50 door : req.body.door 51 }); 52 53 car.save(function(err, car){ 54 if(err) { 55 return res.status(500).json({ 56 message: 'Error saving car', 57 error: err 58 }); 59 } 60 return res.json({ 61 message: 'saved', 62 _id: car._id 63 }); 64 }); 65 }, 66 67 /** 68 * carController.update() 69 */ 70 update: function(req, res) { 71 var id = req.params.id; 72 carModel.findOne({_id: id}, function(err, car){ 73 if(err) { 74 return res.status(500).json({ 75 message: 'Error saving car', 76 error: err 77 }); 78 } 79 if(!car) { 80 return res.status(404).json({ 81 message: 'No such car' 82 }); 83 } 84 85 car.color = req.body.color ? req.body.color : car.color; 86 car.door = req.body.door ? req.body.door : car.door; 87 88 car.save(function(err, car){ 89 if(err) { 90 return res.status(500).json({ 91 message: 'Error getting car.' 92 }); 93 } 94 if(!car) { 95 return res.status(404).json({ 96 message: 'No such car' 97 }); 98 } 99 return res.json(car); 100 }); 101 }); 102 }, 103 104 /** 105 * carController.remove() 106 */ 107 remove: function(req, res) { 108 var id = req.params.id; 109 carModel.findByIdAndRemove(id, function(err, car){ 110 if(err) { 111 return res.status(500).json({ 112 message: 'Error getting car.' 113 }); 114 } 115 return res.json(car); 116 }); 117 } 118};
You then only have to add router in app.js file and MongoDB connection whit Mongoose. app.js :
1var routes = require('./routes/index'); 2var cars = require('./routes/cars'); 3 ... 4 5app.use('/', routes); 6app.use('/cars', cars); 7 ... 8
Copyright (c) 2014 Damien Perrier Licensed under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More