node-express-jwt-project-scaffolding
v1.0.0
Published
A CLI tool to scaffold Node.js + Express + JWT authentication projects
Maintainers
Readme
node-express-jwt-project-scaffolding
A CLI tool that creates a ready-to-use Node.js + Express + JWT authentication project. This is like create-react-app but for backend projects with authentication built-in.
Features
✨ Zero Configuration - Just run one command and get a complete backend project
🔐 JWT Authentication - User registration, login, and token verification ready to use
📁 Clean Architecture - Well-organized folder structure with best practices
🚀 TypeScript Support - Fully typed codebase
💾 TypeORM Integration - Database models and migrations ready
📝 Logging - Winston logger pre-configured
🛡️ Security - Helmet, CORS, and security best practices included
🎯 Role-Based Access - Middleware for role-based authorization
Installation
Install globally using npm:
npm install -g node-express-jwt-project-scaffoldingOr use with npx (no installation needed):
npx node-express-jwt-project-scaffolding my-backend-apiUsage
Create a new project:
node-express-jwt-project-scaffolding my-backend-apiThis will create a new directory my-backend-api with all the boilerplate code.
Quick Start
After creating your project:
cd my-backend-api
npm installConfigure Environment Variables
Edit the .env file with your database credentials:
PORT=3000
NODE_ENV=development
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_USER=postgres
DATABASE_PASSWORD=your_password
DATABASE_NAME=myapp_db
JWT_SECRET=your_super_secret_key_change_this
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your_refresh_secret_keyStart Development Server
npm run devYour server will start at http://localhost:3000
Project Structure
my-backend-api/
├── src/
│ ├── app.ts # Express app configuration
│ ├── index.ts # Entry point
│ ├── datasource.ts # TypeORM configuration
│ ├── routes.ts # API routes
│ ├── common/
│ │ ├── interceptors/
│ │ │ └── requestLogger.ts
│ │ ├── middlewares/
│ │ │ ├── authMiddleware.ts
│ │ │ ├── errorHandler.ts
│ │ │ ├── logger.middleware.ts
│ │ │ └── roleGuard.ts
│ │ └── utils/
│ │ └── jwt.ts
│ ├── modules/
│ │ ├── auth/
│ │ │ ├── auth.controller.ts
│ │ │ ├── auth.service.ts
│ │ │ └── dto/
│ │ └── users/
│ │ ├── user.entity.ts
│ │ ├── users.controller.ts
│ │ ├── users.service.ts
│ │ └── dto/
│ └── shared/
│ └── utils/
│ ├── customResponse.ts
│ ├── logger.ts
│ └── constants/
├── .env
├── package.json
└── tsconfig.jsonAPI Endpoints
Authentication
Send OTP
POST /api/auth/send-otp
Content-Type: application/json
{
"mobile": "1234567890"
}Signup
POST /api/auth/signup
Content-Type: application/json
{
"mobile": "1234567890",
"otp": "123456",
"name": "John Doe",
"email": "[email protected]"
}Login
POST /api/auth/login
Content-Type: application/json
{
"mobile": "1234567890",
"otp": "123456"
}Protected Routes
Get User Profile
GET /api/users/profile
Authorization: Bearer <your_access_token>Available Scripts
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Run production servernpm run typeorm- Run TypeORM CLI commands
Technologies Used
- Node.js - Runtime environment
- Express - Web framework
- TypeScript - Type-safe JavaScript
- TypeORM - ORM for database operations
- PostgreSQL - Database
- JWT - Authentication tokens
- Winston - Logging
- Helmet - Security middleware
- CORS - Cross-origin resource sharing
- Morgan - HTTP request logger
Development Notes
OTP Verification
By default, the OTP is printed to the console. For production:
- Integrate an SMS provider (Twilio, AWS SNS, etc.)
- Replace the console.log in
auth.service.ts - Consider using Redis to store OTPs with TTL
Database
The project uses PostgreSQL by default. To use a different database:
- Install the appropriate driver
- Update
datasource.tswith the new configuration
Security Recommendations
- Change JWT secrets in production
- Set
synchronize: falsein TypeORM for production - Use environment-specific .env files
- Enable HTTPS in production
- Implement rate limiting
- Add input validation using class-validator
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you have any questions or issues, please open an issue on GitHub.
Happy Coding! 🚀
