Production-ready microservices architecture with Node.js, Express, and RESTful APIs. Built for scalability and maintainability.
- π RESTful API endpoints
- π Authentication & Authorization
- π Database integration
- π Error handling & logging
- π§ͺ Unit tests included
- π¦ Modular architecture
- π³ Docker ready
git clone https://github.com/YOUR_USERNAME/backend-microservices.git
cd backend-microservices
npm installCreate .env file:
PORT=3000
NODE_ENV=development
DATABASE_URL=mongodb://localhost:27017/myapp
JWT_SECRET=your-secret-key# Development
npm run dev
# Production
npm start
# Tests
npm testbackend-microservices/
βββ README.md # Documentation
βββ package.json # Dependencies
βββ server.js # Main server
βββ routes.js # API routes
βββ middleware.js # Middleware functions
βββ database.js # Database connection
βββ .gitignore # Git ignore
GET /health
Response: { status: "ok", timestamp: "..." }
GET /api/users # Get all users
GET /api/users/:id # Get user by ID
POST /api/users # Create user
PUT /api/users/:id # Update user
DELETE /api/users/:id # Delete user
POST /api/auth/register # Register new user
POST /api/auth/login # Login user
POST /api/auth/logout # Logout user
GET /api/products # Get all products
GET /api/products/:id # Get product by ID
POST /api/products # Create product
PUT /api/products/:id # Update product
DELETE /api/products/:id # Delete product
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "secret123"
}'curl http://localhost:3000/api/userscurl -X PUT http://localhost:3000/api/users/123 \
-H "Content-Type: application/json" \
-d '{
"name": "Jane Doe"
}'curl -X DELETE http://localhost:3000/api/users/123POST /api/auth/register
{
"email": "user@example.com",
"password": "password123",
"name": "User Name"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": { "id": 1, "email": "user@example.com" }
}POST /api/auth/login
{
"email": "user@example.com",
"password": "password123"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": { "id": 1, "email": "user@example.com" }
}// Add Authorization header
Authorization: Bearer <token>Logs all incoming requests with timestamp, method, and URL.
Catches and formats errors with proper status codes.
Enables Cross-Origin Resource Sharing for frontend integration.
Validates JWT tokens for protected routes.
const db = require('./database');
// Connect
await db.connect();
// Query
const users = await db.query('SELECT * FROM users');
// Insert
await db.insert('users', { name: 'John', email: 'john@example.com' });// User Model
{
id: Number,
name: String,
email: String,
password: String (hashed),
createdAt: Date,
updatedAt: Date
}
// Product Model
{
id: Number,
name: String,
description: String,
price: Number,
stock: Number,
createdAt: Date
}# Run all tests
npm test
# Run specific test
npm test -- routes.test.js
# Coverage report
npm run test:coveragedescribe('Users API', () => {
test('GET /api/users returns users', async () => {
const response = await request(app).get('/api/users');
expect(response.status).toBe(200);
expect(response.body).toBeInstanceOf(Array);
});
});# Server
PORT=3000
NODE_ENV=production
# Database
DATABASE_URL=mongodb://localhost:27017/myapp
DB_HOST=localhost
DB_PORT=5432
DB_NAME=myapp
DB_USER=admin
DB_PASSWORD=secret
# JWT
JWT_SECRET=your-secret-key
JWT_EXPIRES_IN=7d
# CORS
CORS_ORIGIN=http://localhost:3001- Request logging with timestamps
- Error handling with status codes
- Database connection pooling
- Response compression
- Rate limiting (optional)
# Build image
docker build -t backend-microservices .
# Run container
docker run -p 3000:3000 -e DATABASE_URL=... backend-microservices
# Docker Compose
docker-compose up- Password hashing (bcrypt)
- JWT token authentication
- Input validation
- SQL injection prevention
- XSS protection
- CORS configuration
- Rate limiting
{
"express": "^4.18.0",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"jsonwebtoken": "^9.0.0",
"bcrypt": "^5.1.0"
}- Fork the repository
- Create feature branch (
git checkout -b feature/amazing) - Commit changes (
git commit -m 'Add feature') - Push to branch (
git push origin feature/amazing) - Open Pull Request
MIT License - see LICENSE file
- Express.js team
- Node.js community
- Open source contributors
Made with β€οΈ for backend developers
- Frontend:
frontend-components-library - Docker:
docker-deployment-configs - API Testing:
api-testing-framework
CONFIG_VALUE = 'new_value'
@decorator def enhanced_function(): """Enhanced functionality""" return improved_result()
if not input_value: return default_value return process(input_value)
CONFIG_VALUE = 'new_value'
@decorator def enhanced_function(): """Enhanced functionality""" return improved_result()
@decorator def enhanced_function(): """Enhanced functionality""" return improved_result()