Generate CRUD controllers for your express application!
npm install curdy --save
Checkout the example curdy app.
const mongoose = require('mongoose');
module.exports = mongoose.model('SimpleModel', new mongoose.Schema({
string: String,
number: Number,
date: Date,
boolean: Boolean
}, {
timestamps: true,
}));
const curdy = require('curdy');
const SimpleModel = require('./simpleModel.model');
module.exports = curdy.generateController(
SimpleModel, // Model
{
find: { // Find Template
_id: 'params._id'
},
operation: { // Operation Template
string: 'body.string',
number: 'body.number',
boolean: 'body.boolean'
},
render: { // Render Template
_id: '_id',
string: 'string',
number: 'number',
boolean: 'boolean'
}
}
);
const express = require('express');
const Controller = require('./simpleModel.controller');
const router = express.Router();
const curdy = require('curdy');
router.use('/', curdy.generateRoutes(Controller));
// This creates the following routes
// GET / This is the showAll route, returning all models
// GET /:_id This is the show route, returning the model matched by the find
// POST / This is the create route, allowing the user to create a new model
// PUT /:_id This is the update route, allowing the user update a model
// DELETE /:_id This is the delete route, allowing the user delete a model
module.exports = router;
- Easy to install
- Easy to override and extend
- Make working with CRUD simpler and faster.
Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.
Built with ❤️ at Hubba.