2

I m actually developping a REST API using Node.js and Express 4.0 and I wanted to clarify something.

The service is actually working, but in a single javascript file, and I m looking for a good way to cut it into multiples parts.

I was thinking about MVC, but with the actual route system, what is the controller ? Is it the declaration function of the route ?

How can I separate the different route into multiple files ? (like user_routes, billing_routes) etc... I know how to export module etc... but having app = express() in multiple file seems to not work (different instanciation) And where to start to the listen the part ?

These are beginner questions, but please, but explicit :-)

Thanks for advance

mfrachet
  • 8,772
  • 17
  • 55
  • 110

1 Answers1

2

You can check out some these examples:

mvc: https://github.com/visionmedia/express/tree/master/examples/mvc and route-separation: https://github.com/visionmedia/express/tree/master/examples/route-separation

Also here there are 2 good posts on SO about the subject:

https://stackoverflow.com/a/13611448/2846161

ExpressJS How to structure an application?

Community
  • 1
  • 1
Leonardo Lanchas
  • 1,616
  • 1
  • 15
  • 37