Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.js Project Structure

I found that Express has an application generator, however the documentation does not explain the purpose of each directory and file. If someone could just give me a short explanation of which files I should be putting where, that would be much appreciated. Here's the generated app structure:

├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.jade
    ├── index.jade
    └── layout.jade

7 directories, 9 files
like image 874
pzp Avatar asked Feb 13 '15 12:02

pzp


People also ask

Is Express JS good for big projects?

Middleware frameworks, like Express. js, are suitable for small and medium projects. If you are going to develop a large project that will be supported by a large team of developers, Express. js is not the best choice.

Is Express JS good for production?

It's fast, unopinionated, and has a large community behind it. It is easy to learn and also has a lot of modules and middleware available for use. Express is used by big names like Accenture, IBM, and Uber, which means it's also great in a production environment.


1 Answers

The app.js file is the entry-point of your application.

The package.json file contains all of your dependencies and various details regarding your project.

The bin folder should contain the various configuration startup scripts for your application.

For example, instead of applying all the Express middleware in the app.js file, you module.exports = {} them from their own configuration file and require them in app.js. [additional info LINK]

The views folder contains all of your server-side views.

The public folder contains all of your front-end code.

The routes folder contains all the routes that you have created for your application.

As stated in the official documentation, be aware that this is just one way to organize your code.

You should test it out and see if it fits your project.

like image 151
vladzam Avatar answered Oct 22 '22 15:10

vladzam