nxpress-cli
v1.0.2
Published
A CLI tool to generate customizable Node.js + Express.js backend projects
Maintainers
Readme
🚀 Nxpress CLI
A powerful CLI tool to generate customizable Node.js + Express.js backend projects in seconds
📋 Table of Contents
- ✨ Features
- 🚀 Quick Start
- 📦 Installation
- 🛠️ Usage
- ⚙️ Configuration Options
- 📁 Project Structure
- 🔧 API Documentation
- 🧪 Testing
- 🐳 Docker Support
- 📚 Documentation
- 🤝 Contributing
- 📄 License
- 👨💻 Author
- 🙏 Acknowledgments
✨ Features
🎯 Core Features
- 🏗️ Interactive Project Generation - Customizable backend projects with guided setup
- 🗄️ Multiple Database Support - MongoDB, PostgreSQL, SQLite, or no database
- 🔐 JWT Authentication - Complete auth system with registration, login, and protected routes
- 📡 Real-time Communication - Socket.io integration for live features
- 📖 API Documentation - Auto-generated Swagger/OpenAPI documentation
- 🛡️ Security First - Rate limiting, CORS, helmet, input validation, and XSS protection
- 🧪 Testing Ready - Jest and Supertest configuration with example tests
- 📊 Logging System - Winston logger with file rotation and multiple levels
🚀 Advanced Features
- ⚡ Redis Support - Caching and session management
- 🐳 Docker Ready - Complete containerization setup
- 📝 TypeScript Support - Optional TypeScript configuration
- 🔄 CI/CD Templates - GitHub Actions workflows
- 📈 Monitoring - Health checks and performance monitoring
- 🎨 Code Quality - ESLint, Prettier, and Git hooks
🏆 What Makes It Special
- Zero Configuration - Works out of the box with sensible defaults
- Production Ready - Enterprise-grade architecture and security
- Modular Design - Clean separation of concerns and scalable structure
- Developer Experience - Hot reloading, debugging support, and comprehensive documentation
- Community Driven - Open source with active community support
🚀 Quick Start
Get your backend project up and running in under 2 minutes:
# Create a new backend project
npx nxpress-cli my-awesome-api
# Navigate to your project
cd my-awesome-api
# Start development server
npm run devYour API will be running at http://localhost:3000 with:
- 📖 API Documentation:
http://localhost:3000/api/docs - 🏥 Health Check:
http://localhost:3000/api/health - 🔐 Authentication endpoints ready to use
📦 Installation
Prerequisites
- Node.js >= 14.0.0
- npm >= 6.0.0 or yarn >= 1.22.0
- Git (for version control)
Global Installation (Recommended)
npm install -g nxpress-cliOne-time Usage
npx nxpress-cli my-project-nameLocal Development
git clone https://github.com/imankii01/nxpress-cli.git
cd nxpress-cli
npm install
npm link🛠️ Usage
Interactive Mode
nxpress-cli my-apiThe CLI will guide you through customization options:
🚀 Welcome to Nxpress CLI v1.0.0
🛠️ Let's customize your backend project:
? Choose a database: (Use arrow keys)
❯ MongoDB (Mongoose)
PostgreSQL (Sequelize)
SQLite (better-sqlite3)
None
? Include Socket.io support? (y/N)
? Add API documentation (Swagger)? (Y/n)
? Setup JWT Authentication? (Y/n)
? Add Redis support? (y/N)
? Include rate limiting & security? (Y/n)
? Setup testing framework? (Y/n)
? Add logging with Winston? (Y/n)
? Use TypeScript? (y/N)
? Include Docker configuration? (y/N)Command Line Arguments
# Specify project name directly
nxpress-cli my-project
# Get help
nxpress-cli --help
# Check version
nxpress-cli --version⚙️ Configuration Options
Database Options
| Option | Description | ORM/ODM | Features | |--------|-------------|---------|----------| | MongoDB | NoSQL document database | Mongoose | Schema validation, middleware, population | | PostgreSQL | Relational database | Sequelize | Migrations, associations, transactions | | SQLite | Lightweight SQL database | better-sqlite3 | File-based, zero-config, fast | | None | No database | - | API-only, external services |
Feature Matrix
| Feature | Description | Dependencies |
|---------|-------------|--------------|
| JWT Auth | Complete authentication system | jsonwebtoken, bcryptjs |
| Socket.io | Real-time communication | socket.io |
| Swagger | API documentation | swagger-ui-express, swagger-jsdoc |
| Redis | Caching and sessions | redis |
| Security | Rate limiting, validation | express-rate-limit, helmet |
| Testing | Unit and integration tests | jest, supertest |
| Logging | Structured logging | winston |
| TypeScript | Type safety | typescript, @types/* |
| Docker | Containerization | Dockerfile, docker-compose.yml |
📁 Project Structure
my-awesome-api/
├── 📁 src/
│ ├── 📁 controllers/ # Request handlers
│ │ ├── authController.js # Authentication logic
│ │ ├── userController.js # User management
│ │ └── index.js # Controller exports
│ ├── 📁 routes/ # API routes
│ │ ├── auth.js # Auth endpoints
│ │ ├── users.js # User endpoints
│ │ ├── health.js # Health check
│ │ └── index.js # Route aggregation
│ ├── 📁 middlewares/ # Custom middleware
│ │ ├── auth.js # JWT verification
│ │ ├── errorHandler.js # Global error handling
│ │ ├── rateLimiter.js # Rate limiting
│ │ └── validation.js # Input validation
│ ├── 📁 services/ # Business logic
│ │ ├── authService.js # Auth operations
│ │ ├── userService.js # User operations
│ │ └── emailService.js # Email functionality
│ ├── 📁 models/ # Data models
│ │ ├── User.js # User model
│ │ └── index.js # Model exports
│ ├── 📁 sockets/ # Socket.io handlers
│ │ ├── socketManager.js # Connection management
│ │ └── 📁 events/ # Event handlers
│ ├── 📁 utils/ # Utility functions
│ │ ├── logger.js # Winston configuration
│ │ ├── database.js # DB connection
│ │ ├── helpers.js # Helper functions
│ │ └── constants.js # App constants
│ ├── 📁 config/ # Configuration files
│ │ ├── database.js # DB configuration
│ │ ├── redis.js # Redis configuration
│ │ ├── swagger.js # API documentation
│ │ └── index.js # Config aggregation
│ └── app.js # Express app setup
├── 📁 tests/ # Test files
│ ├── 📁 controllers/ # Controller tests
│ ├── 📁 routes/ # Route tests
│ └── setup.js # Test configuration
├── 📁 public/ # Static files
├── 📁 docs/ # Documentation
├── 🐳 Dockerfile # Docker configuration
├── 🐳 docker-compose.yml # Multi-container setup
├── 📄 .env.example # Environment template
├── 📄 .gitignore # Git ignore rules
├── 📄 .eslintrc.js # ESLint configuration
├── 📄 .prettierrc # Prettier configuration
├── 📄 jest.config.js # Jest configuration
├── 📄 swagger.yaml # API specification
├── 📄 README.md # Project documentation
├── 📄 package.json # Dependencies and scripts
└── 📄 server.js # Application entry point🔧 API Documentation
Authentication Endpoints
// Register a new user
POST /api/v1/auth/register
{
"name": "John Doe",
"email": "[email protected]",
"password": "securePassword123"
}
// Login user
POST /api/v1/auth/login
{
"email": "[email protected]",
"password": "securePassword123"
}
// Get current user (Protected)
GET /api/v1/auth/me
Headers: { "Authorization": "Bearer <jwt_token>" }User Management
// Get all users (Protected)
GET /api/v1/users
// Get user by ID (Protected)
GET /api/v1/users/:id
// Update user (Protected)
PUT /api/v1/users/:id
{
"name": "Updated Name",
"email": "[email protected]"
}
// Delete user (Protected)
DELETE /api/v1/users/:idHealth Check
// System health status
GET /api/health
Response: {
"status": "OK",
"timestamp": "2024-01-15T10:30:00.000Z",
"uptime": 3600,
"database": "connected",
"redis": "connected"
}Interactive API Documentation
Visit http://localhost:3000/api/docs for the complete Swagger UI documentation with:
- 📝 Interactive API testing
- 📋 Request/response schemas
- 🔐 Authentication testing
- 📊 Example requests and responses
🧪 Testing
Running Tests
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Run specific test file
npm test -- auth.test.jsTest Structure
// Example controller test
describe('Auth Controller', () => {
describe('POST /api/v1/auth/register', () => {
it('should register a new user', async () => {
const userData = {
name: 'Test User',
email: '[email protected]',
password: 'password123'
};
const response = await request(app)
.post('/api/v1/auth/register')
.send(userData)
.expect(201);
expect(response.body.success).toBe(true);
expect(response.body.data.user.email).toBe(userData.email);
});
});
});Coverage Reports
Tests generate coverage reports in the coverage/ directory:
- HTML Report:
coverage/lcov-report/index.html - JSON Report:
coverage/coverage-final.json - Text Summary: Displayed in terminal
🐳 Docker Support
Quick Start with Docker
# Build and run with Docker Compose
docker-compose up --build
# Run in production mode
docker-compose -f docker-compose.prod.yml up --build
# Run only the database
docker-compose up databaseDocker Configuration
# Multi-stage Dockerfile for optimized builds
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
FROM node:18-alpine AS runtime
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
EXPOSE 3000
CMD ["npm", "start"]Environment Variables
# Database Configuration
DATABASE_URL=mongodb://localhost:27017/myapp
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=admin
DB_PASS=password
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRE=7d
# Redis Configuration
REDIS_URL=redis://localhost:6379
REDIS_HOST=localhost
REDIS_PORT=6379
# Application Configuration
NODE_ENV=development
PORT=3000
API_VERSION=v1
# Email Configuration (if using email service)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASS=your-app-password🤝 Contributing
We welcome contributions from the community! Here's how you can help:
🐛 Reporting Issues
- Check existing issues first
- Use the issue template
- Provide detailed reproduction steps
- Include system information
🔧 Development Setup
# Fork and clone the repository
git clone https://github.com/imankii01/nxpress-cli.git
cd nxpress-cli
# Install dependencies
npm install
# Link for local development
npm link
# Run tests
npm test
# Test the CLI locally
nxpress-cli test-project📝 Pull Request Process
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📋 Code Standards
- Follow ESLint configuration
- Write tests for new features
- Update documentation
- Use conventional commit messages
- Ensure all tests pass
🎯 Areas for Contribution
- 🆕 New database adapters
- 🔌 Additional middleware options
- 📚 Documentation improvements
- 🐛 Bug fixes and optimizations
- 🧪 Test coverage improvements
- 🌐 Internationalization
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 Ankit Singh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.👨💻 Author
Ankit Singh (@imankii01)
Full Stack Developer & Open Source Enthusiast
🙏 Acknowledgments
🌟 Special Thanks
- Express.js Team - For the amazing web framework
- MongoDB Team - For the powerful database solution
- Socket.io Team - For real-time communication capabilities
- Jest Team - For the excellent testing framework
- Open Source Community - For continuous inspiration and support
🛠️ Built With
- Node.js - JavaScript runtime
- Express.js - Web framework
- Commander.js - CLI framework
- Inquirer.js - Interactive prompts
- Chalk - Terminal styling
- Ora - Loading spinners
💡 Inspiration
This project was inspired by the need for a comprehensive, production-ready backend generator that follows modern best practices and provides developers with a solid foundation for building scalable APIs.
🌟 Star this repository if it helped you!
Made with ❤️ by Ankit Singh
