简体   繁体   中英

Structure Node.js (Express) app

How should I structure Node.js (Express) app? I do so:

  • app.js - starting the server
  • router.js - routing requests and starting functions from other files.
  • pages.js - render not-static pages. Example: request to database and render result
  • control.js - operation with alteration. Example: creation/updating line in database.
  • db.js - connection to database and creation model for ORM.

What should be changed? How to do better?

(Sorry for bad english)

Have you heard about Yeoman ? It is a webapp generator, which is a very useful tool to automatically build webapp skeletons.

There are a lot of different generators of any web technology/framework you wish to use. Maybe a good idea can be having a look and exploring how these generators structure the code for you, which could give you an idea in how to keep your code organized.

You can Search for generators at Yeoman 's site, just type Express and try different ones.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM