Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active December 2, 2023 08:47
Show Gist options
  • Star 38 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save miguelmota/7728274 to your computer and use it in GitHub Desktop.
Save miguelmota/7728274 to your computer and use it in GitHub Desktop.
Node.js MVC directory structure example.
Node.js MVC directory structure example.
├── app
│   ├── controllers
│   │   ├── admin
│   │   │   ├── posts.js
│   │   │   └── users.js
│   │   ├── posts.js
│   │   ├── session.js
│   │   └── users.js
│   ├── helpers
│   │   └── posts.js
│   ├── models
│   │   ├── post.js
│   │   └── user.js
│   └── views
│       ├── admin
│       │   └── posts
│       │       ├── edit.jade
│       │       ├── index.jade
│       │       └── new.jade
│       ├── layouts
│       │   └── application.jade
│       └── posts
│           ├── index.jade
│           └── show.jade
├── config
│   ├── application.js
│   ├── express.js
│   ├── middlewares
│   └── routes.js
├── lib
├── node_modules
├── package.json
├── public
│   ├── css
│   │   └── style.css
│   ├── img
│   │   └── logo.png
│   └── js
│       └── main.js
├── server.js
├── spec
│   ├── acceptance
│   │   ├── loginSpec.js
│   │   ├── postsSpec.js
│   │   └── signupSpec.js
│   ├── helper.js
│   └── models
│       ├── postSpec.js
│       └── userSpec.js
└── test
@Dentrax
Copy link

Dentrax commented Oct 21, 2017

Is it recommended that both the Web-Server and the API-Server be in the same structure? Or should be coding as separate folders ? (node-web-server, node-api-server, etc.) Thanks...

@paper-krane
Copy link

Beautiful layout and just what I was looking for. Thanks!

@eylonshm
Copy link

Exactly what I was looking for. Thank you!

@kahramanX
Copy link

Thank you!

@canavci2016
Copy link

you might add service directory at the same level as controller , hence you will be able move your bussiness logic on this layer. you would have avoided decoupling or in the future if you would like to move your projects on different platforms such as serverless. it should facilitate this issue. instead of copying pasting bussiness logic . you could call service methods. as it separate from any protocol. it is sort of stand alone structure and abstracted .
we stumble upon this issue. we had to move some of our code on amazon lambda. thanks to this approach we were able to upload whole structure in a short time without dealing with huge problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment