This Node.js script automatically generates a standardized folder structure for an Express.js project. It creates a src
directory with essential subdirectories and files commonly used in Express.js applications.
The script creates the following folder structure:
src/
├── server.js
├── middlewares/
│ ├── joi.validate.js
│ ├── uploads.js
│ └── auth.js
├── config/
│ └── db.config.js
├── routes/
│ └── user.routes.js
├── models/
│ └── user.model.js
├── controllers/
│ └── user/
│ ├── signup.controller.js
│ └── login.controller.js
└── utils/
- Save the script as
index.js
in your project directory. - Make the script executable:
chmod +x index.js
- Run the script:
./index.js
- The script creates the main
src
directory if it doesn't exist. - It then creates subdirectories for middlewares, config, routes, models, controllers, and utils.
- Specific files are created in each subdirectory as needed.
- The script checks for existing folders and files to avoid overwriting.
- Console output provides information about created folders and files.
You can easily modify the subFolders
array and the createFolderStructure
function to adjust the folder structure and files created according to your project needs.
The script changes the current working directory to two levels up before creating the folder structure. Ensure you run it from the appropriate location in your project.
This script uses Node.js built-in modules:
-
fs
for file system operations -
path
for handling file paths
No additional dependencies are required.
This script is provided as-is under the MIT License. Feel free to modify and use it in your projects.