Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to set up routes in Node.js with Express.js

I'd like to know my options for how to structure my routes in Express.js. Here's my apps directory right now:

  ├── public
  │   ├── images
  │   ├── javascripts
  │   │   ├── showLogin.js
  │   │   └── showSignup.js
  │   └── stylesheets
  │       ├── dash.styl
  │       ├── reset.styl
  │       ├── space.styl
  │       ├── style.css
  │       ├── style.styl
  │       └── typography.styl
  ├── routes
  │   └── index.js
  ├── views
  │   ├── dash.jade
  │   ├── index.jade
  │   ├── layout.jade
  │   └── space.jade
  ├── app.js
  └── package.json

Is it best to break up routes/index.js into several single route files? I've tried this, and apparently I'm not much good at it, haha.

Another option is to introduce a lib directory somewhere. Where does one usually do that?

Any other advice would rock!

like image 213
Costa Michailidis Avatar asked Aug 03 '12 04:08

Costa Michailidis


1 Answers

A couple of us at work created a small reference app to codify a standard Express app structure. It's not overly complex or anything, we just tried to create something that was easily understandable, and had structure that would allow the app to grow over time.

You can find it here: https://github.com/EAAppFoundry/tableau

While you're there, feel free to give us feedback. I'm sure it could be improved.

Hope it helps!

like image 178
Don Avatar answered Oct 16 '22 19:10

Don