Skip to content

This tool helps you quickly scaffold a new Node.js application with various optional features like CORS, environment variables, logging, MongoDB integration, and more. πŸš€

License

Notifications You must be signed in to change notification settings

vatsalpipalava/init-node-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Node.js Project Generator | npx init-node-project

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. πŸš€

Table of Contents

Features

  • 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 and winston 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.

Installation

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

Options

  1. Project Name: The name of your project (default: my-node-app).
  2. Enable CORS: Do you want to enable CORS? (default: yes).
  3. Use Environment File: Do you want to use an environment file? (default: yes).
  4. Use Morgan and Winston for Logging: Do you want to use morgan and winston for logging? (default: yes).
  5. Use Basic Response, Error, and Async Handlers: Do you want to use a basic response handler, error handler, and async handler? (default: yes).
  6. Initialize GitHub: Do you want to initialize a GitHub repository? (default: yes).
  7. Enable Prettier: Do you want to enable Prettier? (default: yes).
  8. Connect MongoDB: Do you want to connect a MongoDB database? (default: yes).

Generated Project Structure

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

Dependencies

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.

Scripts

The generated package.json will include the following scripts:

  • dev: Start the development server using nodemon.
{
  "scripts": {
    "dev": "nodemon -r dotenv/config --experimental-json-modules src/index.js"
  }
}

License

This project is licensed under the MIT License.

About

This tool helps you quickly scaffold a new Node.js application with various optional features like CORS, environment variables, logging, MongoDB integration, and more. πŸš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published