mongoose-model-controller
v0.0.1
Published
mongoose model controller
Downloads
5
Readme
mongoose-model-controller
Installation
$ npm install mongoose-model-controller --save
or
$ yarn add mongoose-model-controller
Usage
const mongoose = require('mongoose')
mongoose.connect(process.env.DB_URL, err => {
if (err) return console.error(err)
console.log('mongoose connected')
})
const fields = {
username: String,
email: String
}
const schema = new mongoose.Schema(fields)
const usermodel = mongoose.model('User', schema)
const Controller = require('mongoose-model-controller')
const UserController = new Controller(usermodel)
const express = require('express')
const app = express()
app.get('/users', UserController.findAll())
app.get('/users/:_id', UserController.findOne())
app.post('/users', UserController.create())
app.put('/users/:_id', UserController.update())
app.delete('/users/:_id', UserController.delete())