V
V
Vyacheslav Lebedev2015-05-18 23:00:24
Node.js
Vyacheslav Lebedev, 2015-05-18 23:00:24

How to put all routing into a separate file (module) on Node?

Good evening!
I wondered how to transfer the entire routing to a separate file so that my eyes would not be an eyesore.
For example, there are several.

app.get('/', function(req, res) {
  res.render('index');
});

app.js is the entry point.
Simply taking out and connecting the module does not help, you still need to do some manipulations.
Rescue, Thank you! :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kotofey, 2015-05-18
@slavikse

1. in app.js
2. in your project, create a routes directory and index.js there, in which you write all the routes

module.exports = function (app) {
    app.get('/', function(req, res) {
        res.render('index');
    });
    app.get('/user', function(req, res) {
        res.render('user');
    });
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question