Express.js Project Structure
A scalable and maintainable folder structure for Express.js applications
File Structure
- node_modules
- public
- favicon.ico
- src
- controllers
- userController.js
- models
- user.js
- middlewares
- authMiddleware.js
- routes
- userRoutes.js
- app.js
- package.json
- README.md
Directory Structure Explanation
node_modules
Contains all installed dependencies and packages from npm. This folder is auto-generated by running `npm install`.
public
Stores static assets like images, stylesheets, and JavaScript files accessible by the client.
favicon.ico
A small icon displayed in the browser tab representing the website.
src
Holds the main source code of the application, including routes, controllers, models, and middleware.
controllers
Contains route handlers that process incoming requests and return responses.
userController.js
Handles user-related logic, such as authentication, registration, and profile management.
models
Defines database schemas and structures for storing and retrieving data.
user.js
Defines the schema and model for users, including fields like name, email, and password.
middlewares
Contains middleware functions that process requests before they reach the controller.
authMiddleware.js
Checks authentication and authorization for protected routes.
routes
Defines application routes and maps them to controllers.
userRoutes.js
Contains user-related routes, such as login, signup, and profile endpoints.
app.js
Main application file where Express is initialized, middleware is set up, and routes are registered.
package.json
Holds metadata about the project, dependencies, scripts, and configurations.
README.md
Project documentation with information on how to install, run, and use the application.