Modern, secure backend API for the e-commerce website built with Node.js, Express, and MongoDB.
- Express.js server with comprehensive middleware setup
- MongoDB database with Mongoose ODM
- JWT Authentication with refresh tokens
- Security middleware (Helmet, CORS, Rate limiting)
- Error handling with custom error middleware
- Validation using express-validator
- Logging with Morgan
- Compression for optimized responses
- Environment-based configuration
-
Install dependencies:
npm install
-
Environment variables: Copy
.env.exampleto.envand configure your settings:cp .env.example .env
-
Start MongoDB: Make sure MongoDB is running on your system or update
MONGODB_URIin.env -
Test database connection:
npm run test:db
-
Start development server:
npm run dev
npm start- Start production servernpm run dev- Start development server with nodemonnpm test- Run testsnpm run test:watch- Run tests in watch modenpm run test:db- Test database connectionnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issues
GET /health- Server health status
GET /api- API information and status
src/
├── config/ # Configuration files
│ ├── config.js # App configuration
│ └── database.js # Database connection
├── controllers/ # Route controllers
├── middleware/ # Custom middleware
│ ├── auth.js # Authentication middleware
│ ├── errorHandler.js # Error handling
│ └── validation.js # Validation middleware
├── models/ # Mongoose models
├── routes/ # API routes
├── services/ # Business logic services
├── utils/ # Utility functions
│ ├── asyncHandler.js # Async error handling
│ ├── response.js # Response utilities
│ └── testConnection.js # DB connection test
└── index.js # Server entry point
See .env.example for all required environment variables.
- Helmet - Security headers
- CORS - Cross-origin resource sharing
- Rate limiting - Prevent abuse
- JWT - Secure authentication
- Input validation - Prevent malicious input
- Error handling - Secure error responses
- Implement data models (Product, User, Order, Category)
- Create authentication system
- Build API endpoints for products, users, orders
- Add payment processing integration
- Implement caching with Redis