DEV Community

Discussion on: How to structure your Express and Node.Js project

Collapse
 
flodev profile image
Florian Klenk

Hi, thanks for sharing. I like the structure.
Just did a quick check how my last express project was structured.
The project was quite complex. I had a routes folder too.
But the exports of each folder was an own router object.

routes/
- user/
- order/
- product/
- checkout/
-- submit-order/
-- checkout.js
- ...
Enter fullscreen mode Exit fullscreen mode

Then in the root of the project dir I had the app.js that put the routers together like so:

appRouter.use('/user', require('./routes/user/user'))
appRouter.use('/checkout', require('./routes/checkout/checkout'))
appRouter.use('/product', require('./routes/product/product'))
appRouter.use('/order', require('./routes/order/order'))
Enter fullscreen mode Exit fullscreen mode

One can say that each routes folder was a project on it's own this way like independent.
Great for microservices if you decide to put it into separate services.