mardi 23 juillet 2019

How to Separate Router From Controller in Express App?

I want to separate routes from controller.

I tried this approach:

routes/index.js

var express              = require('express');
var router               = express.Router();
var wordMapperController = require('../controller/wordmapper');

router.get('/', wordMapperController());

module.exports = router;

conroller/wordmapper.js

var __construct = function(req, res, next) {
    res.render('index', { title: 'Word Mapping for Sanskrit-Indonesian in BG' });

    next();
}

module.exports = __construct;

When I start the res is undefined, and prevent the app to be launched. How does I handle this? How is it app.use and handle router middleware being passed?

Aucun commentaire:

Enregistrer un commentaire