Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ sk-nodeexpress

npm version npm downloads Dev.to Article License: MIT GitHub stars

sk-nodeexpress is an ultra-fast, zero-config CLI generator that instantly scaffolds production-ready Node.js & TypeScript Express backend REST APIs.

Say goodbye to spending hours writing repetitive Express boilerplate, JWT authentication logic, Zod validation schemas, environment handling, CORS, Helmet security headers, rate limiting, Docker setups, and database connections from scratch!

๐Ÿ“– Featured Article on Dev.to: Stop Writing Express Boilerplate: Build a Production-Ready REST API in Minutes

SK-NODEEXPRESS CLI Scaffolder

npx sk-nodeexpress my-app

๐Ÿ“Œ Table of Contents


๐Ÿš€ Features

  • โšก Express Server Core: Pre-configured app & server entry point with clean modular architecture.
  • ๐Ÿ“ Dual Language Support: Choose between JavaScript (ES Modules) and TypeScript.
  • ๐Ÿ›ก๏ธ Zod Payload Validation: Integrated Zod validation middleware for all authentication endpoints.
  • ๐Ÿ” Pre-built JWT Authentication:
    • User Registration (POST /api/v1/auth/register)
    • User Login (POST /api/v1/auth/login)
    • Forgot & Reset Password Stubs (POST /api/v1/auth/forgot-password, /reset-password)
    • Protected User Profile (GET /api/v1/auth/me)
    • Password hashing using bcryptjs
    • JWT token generation & Verification Middleware
  • ๐Ÿƒ Database Integration: MongoDB setup using mongoose (User Schema, connection handlers, duplicate key error handling).
  • ๐Ÿณ Docker Ready: Multi-stage Dockerfile and docker-compose.yml for instant containerization.
  • ๐Ÿ›ก๏ธ Production Security & Middlewares:
    • helmet: Protects HTTP headers
    • cors: Handles cross-origin requests
    • express-rate-limit: Prevents DDoS / Brute-force attacks
    • morgan: Request logging
    • cookie-parser: Parses cookies safely
    • Global Error Handling & 404 Route Catchers
  • ๐ŸŽฏ Dynamic File Scaffolding: Strips unused files dynamically based on your selections.

๐Ÿ“Š Comparison Table

Feature sk-nodeexpress express-generator NestJS CLI
TypeScript Native โœ… โŒ โœ…
Pre-built JWT Auth โœ… โŒ โŒ
Zod Input Validation โœ… โŒ Manual
Docker & Compose Setup โœ… โŒ Manual
Security (Helmet/RateLimit) โœ… โŒ Manual
Setup Time < 5s ~30s ~60s
Zero Configuration โœ… โŒ โŒ

๐Ÿ—๏ธ Architecture Flow

graph TD
    Client["๐ŸŒ HTTP Client / Postman"] --> Router["๐Ÿ›ฃ๏ธ Express Router (/api/v1/auth)"]
    Router --> RateLimit["๐Ÿ›ก๏ธ Rate Limiter & Helmet Middleware"]
    RateLimit --> ZodVal["Validating Zod Schema Middleware"]
    ZodVal --> Controller["๐ŸŽฎ Controller Layer (Async Handler Wrapper)"]
    Controller --> Model["๐Ÿƒ Mongoose Model / Bcrypt Password Hash"]
    Model --> Response["๐Ÿ“ฆ Standardized API Response Helper"]
    Response --> Client
Loading

๐Ÿ“ฆ Installation

No global installation is required! Run directly using npx:

npx sk-nodeexpress

Or specify your project name directly:

npx sk-nodeexpress my-express-api

โšก Quick Start & CLI Flags

1. Interactive Mode (Default)

npx sk-nodeexpress my-app

2. Sub-Second Non-Interactive Flags

# JavaScript + MongoDB + Auth + Docker
npx sk-nodeexpress my-app --yes

# TypeScript + MongoDB + Auth + Docker
npx sk-nodeexpress my-ts-app --ts --auth --docker

# Standalone Express Server without Auth/DB
npx sk-nodeexpress my-minimal-app --js --no-auth --db none --no-docker

Supported Flags:

  • --ts / --js: Select language template
  • --auth / --no-auth: Include or exclude JWT Authentication
  • --db <type>: Database type (mongodb or none)
  • --docker / --no-docker: Include or exclude Docker & docker-compose
  • --install / --no-install: Control automatic npm install

๐Ÿ“ Project Structure

Project Structure

my-express-api/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ db.js            # MongoDB Mongoose Connection
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ authController.js# Register, Login, Profile, Password Reset
โ”‚   โ”‚   โ”œโ”€โ”€ userController.js# User management logic
โ”‚   โ”‚   โ””โ”€โ”€ healthController.js # Server healthcheck endpoint
โ”‚   โ”œโ”€โ”€ middlewares/
โ”‚   โ”‚   โ”œโ”€โ”€ authMiddleware.js# JWT Guard & Role verification
โ”‚   โ”‚   โ”œโ”€โ”€ validate.js      # Zod Schema Validator Middleware
โ”‚   โ”‚   โ”œโ”€โ”€ errorMiddleware.js# Global Error & 404 handler
โ”‚   โ”‚   โ””โ”€โ”€ rateLimiter.js   # Rate limiting guards
โ”‚   โ”œโ”€โ”€ validations/
โ”‚   โ”‚   โ””โ”€โ”€ authValidation.js# Zod Validation Schemas
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ””โ”€โ”€ User.js          # Mongoose User Schema & Bcrypt methods
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ authRoutes.js    # Auth endpoints with Zod Guards
โ”‚   โ”‚   โ”œโ”€โ”€ userRoutes.js    # User endpoints
โ”‚   โ”‚   โ””โ”€โ”€ healthRoutes.js  # Health endpoint
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ apiResponse.js   # Standardized JSON response wrapper
โ”‚   โ”‚   โ”œโ”€โ”€ asyncHandler.js  # Async Error Handler Wrapper
โ”‚   โ”‚   โ””โ”€โ”€ jwt.js           # JWT Sign & Verify helpers
โ”‚   โ”œโ”€โ”€ app.js               # Express application setup
โ”‚   โ””โ”€โ”€ server.js            # Server listener
โ”œโ”€โ”€ Dockerfile               # Production Docker Container setup
โ”œโ”€โ”€ docker-compose.yml       # Express API + MongoDB Services setup
โ”œโ”€โ”€ .env.example             # Environment template
โ”œโ”€โ”€ package.json             # App dependencies & npm scripts
โ””โ”€โ”€ README.md                # Generated project documentation

๐Ÿณ Docker Support

Docker Container Setup

To run your API inside a Docker container with MongoDB:

# Build and start containers in detached mode
docker-compose up -d --build

# View container logs
docker-compose logs -f

# Stop containers
docker-compose down

๐Ÿ”ง Environment Variables

PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/my_sknodejs_db
JWT_SECRET=super_secret_jwt_key_change_in_prod
JWT_EXPIRES_IN=7d
CORS_ORIGIN=*

๐Ÿ“š API Example

1. Register User

POST /api/v1/auth/register

{
  "name": "Jane Doe",
  "email": "jane@example.com",
  "password": "password123"
}

2. Login User

POST /api/v1/auth/login

{
  "email": "jane@example.com",
  "password": "password123"
}

โ“ FAQ & Troubleshooting

Q: JWT_SECRET environment variable is missing error?

Ensure you have created a .env file from .env.example and specified a valid JWT_SECRET.

Q: MongoDB Connection Refused?

Ensure MongoDB service is running locally (mongod) or start it via docker-compose up -d mongo.


๐Ÿ—บ๏ธ Roadmap

  • v1.1.0: Zod Validation, Async Process Execution, Docker Support, Non-interactive Flags.
  • v1.2.0: Swagger OpenAPI documentation endpoint (/api-docs).
  • v2.0.0: Prisma ORM Support (PostgreSQL / MySQL).

๐Ÿค Contributing

Please read our Contributing Guide and Code of Conduct before submitting pull requests.


๐Ÿ“„ License

MIT ยฉ Shobhit Kumar

About

Interactive, zero-config CLI generator to instantly scaffold production-ready Node.js & TypeScript Express backend apps pre-configured with JWT Authentication, MongoDB/Mongoose, Helmet Security, Rate Limiting, & Best Practices.

Topics

Resources

Code of conduct

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages