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

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.