Greg Thompson
Greg Thompson

Reputation: 894

Node.js/Express project structure

so I've had strictly a MVC programming background (Laravel, CodeIgniter, Django, etc.) and more and more I'm build bigger projects in Node.js but I'm having a difficult time figuring out a solid way of structuring my project that makes sense...

I've done some research and I love the way J. Cole Morrison does it here but it makes for extremely fat route files.

The structure is something like

app
-router
-index.js (your main route def. that imports individual route files)
--routes

This is nice and readable but all of your logic is stuffed in the routes folder which just doesn't make sense (or does it?). I guess I'd expect something more along the lines of seperate controllers that will handle your thinking. Does anyone else have Ideas or structures they use or is this a good way to go?

Upvotes: 2

Views: 1916

Answers (1)

eddie
eddie

Reputation: 691

After using node.js / express.js in some projects, I have found Kraken's (1.+) structure very useful. It uses folders as part of the routes. Also, it comes with a scaffolding tool, so the mvc structure is easy to keep. This is not the only solution, but it is a good one indeed.

Disclosure: This is copy from kraken.js

/config Application configuration including environment-specific configs

/controllers Routes and logic

/locales Language specific content bundles

/lib Common libraries to be used across your app

/models Models

/public Web resources that are publicly available

/public/templates Server and browser-side templates

/tasks Grunt tasks to be automatically registered by [grunt-config-dir]

/tests Unit and functional test cases

index.js Application entry point

Upvotes: 2

Related Questions