How to NodeJS- Express App directory structure
In this tutorial, we are going to learn Node.js Express app directory structure. The express app has set up with a good organized files and folders structure. The following tree diagram shows the directory structure of the Node.js Express app.
Node.js Express App directory structure
Express App directory tree:
| └── www
├── public //contains your static files that are not handled by any compilers
| ├── images
| └── style sheets
| ├── index.js
| └── users.js
| ├── error.jade
| ├── index.jade
| └── layout.jade
The folder bin is short for binary. It generally refers to the built applications that do something for a specific system. It contains a single file named www.js
www.js is the core file of express app project which creates an HTTP Server and passes app as the handler. In this file, we can configure the listening port for HTTP requests using server.listen(port_number). Port 3000 is the default port used in this file. It also performs error handling while starting the server.
It also performs error handling while starting the server.
This file is the configuration for creating and run the Node.js server. so it is responsible for our project up and running.
Node_modules are the addition modules in addition to core modules. All of the core modules are loading from external libraries. You can any node_modules to the library using package.json. We will discuss it in coming tutorials.
This folder includes all the images and icons to display on the website. Users can access the web pages
It includes all styles and style related files (SCSS or LESS files).
Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method.
The routes directory contains all of the route definitions for your application. By default, two route files are included with the express app: index.js and users.js.
This file is responsible for pages on websites. As the default, a router to the home page already exists.
User.js is responsible for handling user requests to user pages of the website. As the default, when a user request
/users route, app.js handle the request with user.js and respond with the resource.
This is responsible for displaying all or a portion of the data to the user. Jade is an HTML templating engine. All jade files need to be transformed into the HTML.
It responsible for displaying error messages like page not found 404.
Index.jade file include HTML tags and texts to display on home page.
Layout.jade is responsible to extends common page template to unique contents.
App.js id the core foundation of the Node.js project. so essentially whenever a user comes to our website and makes a request. app.js is going to look at the request and it figures out how to handle the response depending on URL.
The package.json is present in the root directory of any Node application/module and is used to define the properties of a package. The package.json file main purpose is to remember your application dependencies and their respective versions.