M
M
myspace2017-02-18 14:44:11
Node.js
myspace, 2017-02-18 14:44:11

Where is the right place to keep node.js application logic?

If you take express, then it is rendered directly in the router

var express = require('express');
var router = express.Router();

router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;

Maybe it would be more correct to return that part of the application that is responsible for the logic of the route, and already render in it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2017-02-18
@myspace

function(req, res, next) {
  res.render('index', { title: 'Express' });
}

you put it in the controller
./controllers/controllerName.js:
module.exports.routeName = function(req, res, next) {
  res.render('index', { title: 'Express' });
};

Connect to app:
const controllerName = require('./controllers/controllerName.js');
router.get('/', controllerName.routeName);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question