A
A
Abc Edc2015-01-25 22:20:41
Node.js
Abc Edc, 2015-01-25 22:20:41

How correct is routes in nodejs(express)?

In general, studying a node and, in general, wanting to make a beautiful AKA REST API structure, I want to immediately do everything without errors, how many correct routes to implement in such a way:

-------
route/index.js
-------
module.exports = function(app) {
 require('../controllers/test1')(app);
 require('../controllers/test2')(app);
 ...
 require('../controllers/testn')(app);
};

and already in the controllers themselves
-------
controllers/test1.js
-------
var Test1 = require('../models/test1').User;
module.exports = function(app) {
   app.get('/test', function (req, res, next) {
mnogo krutogo koda
      
    })
    app.put('/users/:id', function (req, res, next) {
       
    })
....
CRUD
}

Well, the models
-------
models/test1.js
-------
var mongoose = require('../lib/mongoose');
var Schema = mongoose.Schema;
var schema = new Schema({
    testl:{
        type: String,
        unique: true,
        required: true
    },
    test2:{
        type: String,
        required: true
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Puzynya, 2015-01-26
@gleber1

In general, if you do not want to reinvent the wheel, look at ready-made deliberate implementations. For example Loopback, which in the context of your question is a wrapper over express. These guys spent enough time discussing how the rest api should be stored.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question