基于Node和Mongoose开发的Web应用CRUD示例:web-crud

jopen 6年前

基于Node和Mongoose开发的Web应用CRUD示例

  • list
  • create
  • findById
  • update
  • delete

Installation

$ npm install web-crud --save

Example

model/foo.js

'use strict';    const mongoose = require('mongoose');  const Schema = mongoose.Schema;    const FooSchema = new Schema({      name: {          type: String,          default: ''      }  });    module.exports = mongoose.model('Foo', FooSchema);

controller/foo.js

'use strict';    const Model = require('./model/foo');  const Crud = require('web-crud');    Crud.model(Model); // set model mongoose    module.exports = class Foo extends Crud {};

route/foo.js

'use strict';    const express = require('express');  const router = express.Router();  const controller = require('./controller/foo');    router      .route('/')      .get(controller.list)      .post(controller.create)    router      .route('/:id')      .get(controller.findById)      .put(controller.update)      .delete(controller.delete)    module.exports = router;

项目主页:http://www.open-open.com/lib/view/home/1451284961417