Created
June 13, 2019 23:00
-
-
Save Jero786/bdde50951756b0ab3deafa6bd634274b to your computer and use it in GitHub Desktop.
NodeJS + Mongoose + Mongoose-Crudify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const mongoose = require('mongoose'); | |
const mongooseCrudify = require('mongoose-crudify'); | |
const app = express(); | |
const bodyParser = require('body-parser'); | |
const PORT = process.env.PORT || 3000; | |
mongoose.connect('mongodb://localhost/demo', {useNewUrlParser: true}) | |
.then(() => console.log('Connection successfull')) | |
.catch(err => console.error(err)); | |
const BlogSchema = mongoose.Schema({ | |
name:String, | |
email:String, | |
mobile:Number, | |
message:String | |
}, { | |
strict: false | |
}); | |
const BlogModel = mongoose.model('Blog', BlogSchema); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.use('/articles', mongooseCrudify({ | |
Model: BlogModel, | |
beforeActions: [] | |
})); | |
app.get('/', (req, res) => res.send('Hello Brisa!!')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment