简体   繁体   中英

Node.js app structure, “folder by features” routing

I'm making a scalable REST-API, but I barely find articles on advanced node.js application structures in terms of a big application, since most of them are using simple starter projects.

I'm using the " folder-by-feature " structure, based on this article and this answer .

My question: what is the better structure of the solutions bellow ?

1. Keep the routes in a separate folder:

src
  product
    index.js
    product.spec.js
  routes
    index.js
    product.js
    user.js
  user
    index.js
    user.spec.js

2. Put the route into its corresponding folder:

src
  product
    index.js
    product.route.js
    product.spec.js
  user
    index.js
    user.route.js
    user.spec.js

Using the routes in the index.js files.

Are there any better solutions?

Any article about advanced, scalable node project structures would be appreciated!

Since this is an opinion question here is mine:

My build migrates everything from src to dist . Some is compiled and some is just copied. I then run directly from the dist folder.

src
  api
    <api files/folders>
  lib
    <common lib files/folders>
  routes
    <Route files (app.use, app.get, etc.)>
  static
    <static css, images, script, etc.>
    <I do not include src code that is compiled in any way>
  ui
    <LESS, SASS, JS, etc that will be compiled, combined, packed, etc>
  views
    <ejs files>
  app.js

Things in src/ui/** get compiled and placed into dist/static/** .

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