Welcome to the Node.js Project Generator! This tool helps you quickly scaffold a new Node.js application with various optional features like CORS, environment variables, logging, MongoDB integration, and more. π
- Project Setup: Quickly sets up a new Node.js project directory with necessary subdirectories.
- CORS: Option to enable CORS with configurable origins.
- Environment Variables: Option to use a
.env
file for environment-specific configurations. - Logging: Option to integrate
morgan
andwinston
for logging. - Response, Error, and Async Handlers: Option to include basic response, error, and async handlers.
- GitHub Integration: Option to initialize a Git repository with a pre-configured
.gitignore
and.gitattributes
. - Prettier: Option to enable Prettier for code formatting.
- MongoDB: Option to connect a MongoDB database with Mongoose.
First, ensure you have Node.js and npm installed on your machine. Then, you can install the project generator globally using npm:
Install my-project with npx
npx init-node-project
- Project Name: The name of your project (default:
my-node-app
). - Enable CORS: Do you want to enable CORS? (default:
yes
). - Use Environment File: Do you want to use an environment file? (default:
yes
). - Use Morgan and Winston for Logging: Do you want to use morgan and winston for logging? (default:
yes
). - Use Basic Response, Error, and Async Handlers: Do you want to use a basic response handler, error handler, and async handler? (default:
yes
). - Initialize GitHub: Do you want to initialize a GitHub repository? (default:
yes
). - Enable Prettier: Do you want to enable Prettier? (default:
yes
). - Connect MongoDB: Do you want to connect a MongoDB database? (default:
yes
).
The generated project will have the following structure:
my-node-app/
β
βββ public/
β βββ temp/
β βββ .gitkeep
β
βββ src/
β βββ config/
β β βββ allowedOrigins.js
β β βββ corsOptions.js
β βββ controllers/
β βββ db/
β β βββ index.js
β βββ logs/
β β βββ app.log
β βββ middlewares/
β β βββ credentials.js
β βββ models/
β βββ routes/
β βββ tests/
β βββ utils/
β β βββ asyncHandler.js
β β βββ ApiResponse.js
β β βββ ApiError.js
β β βββ logger.js
β βββ app.js
β βββ index.js
β
βββ .env
βββ .gitattributes
βββ .gitignore
βββ .prettierrc
βββ .prettierignore
βββ package.json
βββ README.md
Depending on your choices, the generated project may include the following dependencies:
express
: Fast, unopinionated, minimalist web framework for Node.js.cors
: Middleware for enabling CORS.dotenv
: Module to load environment variables from a .env file.mongoose
: MongoDB object modeling tool.winston
: Logger for Node.js.morgan
: HTTP request logger middleware for Node.js.
The generated package.json
will include the following scripts:
dev
: Start the development server usingnodemon
.
{
"scripts": {
"dev": "nodemon -r dotenv/config --experimental-json-modules src/index.js"
}
}
This project is licensed under the MIT License.