1

I'm new to Node.js and am unsure about how to layout some things.

My directory structure is as follows (I'm open to changing this):

- controllers 
- helpers 
- middlewares 
- models 
    - BlockLibraryConfigs.js
    - BlockMosaicStreamer.js
    - GlobalMercator.js 
    - index.js 
    - MosaicStreamer.js
- nbproject 
    - private 
        - private.properties
        - private.xml
    - project.properties 
    - project.xml
- node_modules
    - all installed modules . . . 
- public 
    - images 
    - javascripts 
    - stylesheets 
        - style.css
- tests 
- views 
    - index.jade 
    - layout.jade 
    - view.jade
app.js 
package.json 

The files under models, with the exception of index.js include classes. Is this the right spot for them? If so, I should make them accessible through index.js, right? What's the proper way to go about this?

Sara Fuerst
  • 5,688
  • 8
  • 43
  • 86
  • This is a highly subjective topic (and may run counter to Stack Overflow's [Good question criteria](http://stackoverflow.com/help/how-to-ask).) That said, I've always put source files in a `./src/` folder and then split it up in whatever way makes the most sense for me there. – Mark Apr 18 '16 at 19:50
  • did you try using the express generator? it'll create a skeleton app for you that you can build from. http://expressjs.com/en/starter/generator.html – Abdul Ahmad Apr 18 '16 at 19:56

1 Answers1

1

This is a perfectly reasonable layout keeping in mind that there isn't no one true way. You can either manually have your models/index.js include and export them, or just use require-directory from NPM. Obviously as your project grows in complexity your layout may get more complex as you divide up views and your javascript folder.

Also note that the plural of middleware is still just middleware, likewise for javascript.

Kyros
  • 512
  • 2
  • 5