Handling user request / routes in the express framework

+1 Zion Ben Yacov · March 1, 2016
Hi,
It seems to be very weird that each time I create a new page or route I need to add it to the app.js
In that case, if I have a website with hundreds of pages, then the app.js will contain lots and lots of code lines just for the routes

Is there any way to do it like MVC, when the code decide which "controller" (in the nodejs way, route)  to initial

Post a Reply

Replies

Oldest  Newest  Rating
0 Vikas Goswami · June 26, 2016
I am also waiting for same answer.
0 Dol Lod · April 8, 2017
Sorry about the late response, but of course this can be done very carefully through routing. You can map certain paths onto routers. Then within those router files, you can get more specific. If this isn't very clear, here is an example. You have 3 parts to your site: /, /a, /a/s, /b

Here is the main router: path associations are ('/a',RouterName), ('b',RouterName) where both of these routers are the routers located within their own files. Then within a's routing file there would be something containing /s.
  • 1

Node.js

94 followers
About

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Links
Moderators