perfect-node-structure
v1.0.3
Published
A Node.js project structure generator
Downloads
275
Maintainers
Keywords
Readme
Express.js Project Structure Generator
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.
Folder Structure
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/
Usage
- Save the script as
index.js
in your project directory. - Make the script executable:
chmod +x index.js
- Run the script:
./index.js
Functionality
- 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.
Customization
You can easily modify the subFolders
array and the createFolderStructure
function to adjust the folder structure and files created according to your project needs.
Note
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.
Dependencies
This script uses Node.js built-in modules:
fs
for file system operationspath
for handling file paths
No additional dependencies are required.
License
This script is provided as-is under the MIT License. Feel free to modify and use it in your projects.