Answer the question
In order to leave comments, you need to log in
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);
};
-------
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
}
-------
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
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 questionAsk a Question
731 491 924 answers to any question