This is a starter template for building REST APIs with Node.js, Express, and TypeScript. It provides authentication, user management, and core backend functionality using MongoDB with Mongoose as the database layer.
- 🚀 TypeScript - Full TypeScript support with strict type checking
- 🌐 REST API - RESTful API built with Express.js
- 🔐 JWT Authentication - Secure authentication with JSON Web Tokens
- 👤 User Management - User registration, login, and profile management
- 🗄️ MongoDB - Database with Mongoose ODM
- 🐳 Docker Support - Containerized development environment
- 🧹 Code Quality - ESLint & Prettier for consistent code style
- 🧪 Testing - Unit tests with Jest and Supertest
- 📝 Logging - Structured logging for debugging and monitoring
- 🔄 Auto-reload - Development server with hot reload
- Runtime: Node.js
- Language: TypeScript
- Framework: Express.js
- Database: MongoDB with Mongoose
- Authentication: JWT + bcryptjs
- Development: Nodemon, ts-node
- Testing: Jest, Supertest
- Code Quality: ESLint, Prettier
- Containerization: Docker & Docker Compose
- Node.js (v18+ recommended)
- Docker & Docker Compose
- MongoDB (if running locally)
git clone https://github.com/your-username/node-and-express.git
cd node-and-express# Using npm
npm install
# Using yarn
yarn installCopy the example environment file and update the values:
cp .env.example .envUpdate .env with your configuration:
PORT=5000
JWT_SECRET=your_super_secret_jwt_key_here
DB_URI=mongodb://mongo:27017/nodeapp# Start all services (API + MongoDB)
docker-compose up --build
# Run in background
docker-compose up -d --build# Make sure MongoDB is running locally, then:
yarn devThe API will be available at http://localhost:5000
# Development
yarn dev # Start development server with hot reload
yarn dev:simple # Start with basic nodemon setup
# Building
yarn build # Compile TypeScript to JavaScript
yarn start # Run compiled JavaScript (production)
# Code Quality
yarn lint # Run ESLint
yarn format # Format code with Prettier
# Testing
yarn test # Run test suiteGET /health- API health status
POST /auth/register- User registrationPOST /auth/login- User login
node-and-express/
├── .github/
│ └── copilot-instructions.md # GitHub Copilot configuration
├── scripts/
│ ├── dev.js # Development server script
│ └── dev.sh # Shell script for development
├── src/
│ ├── controllers/ # Route controllers
│ │ └── authController.ts
│ ├── models/ # Mongoose models and schemas
│ │ └── user.ts
│ ├── routes/ # Express route definitions
│ │ ├── auth.ts
│ │ ├── health.ts
│ │ └── routes.ts
│ ├── services/ # Business logic layer
│ │ └── authService.ts
│ ├── utils/ # Helper functions
│ │ ├── jwt.ts
│ │ └── logger.ts
│ └── index.ts # Application entry point
├── docker-compose.yml # Docker services configuration
├── Dockerfile # Docker image configuration
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration- All application code must be written in TypeScript
- Use async/await for asynchronous operations
- Follow ESLint and Prettier configurations
- Use proper error handling with try-catch blocks
- Controllers: Handle HTTP requests/responses, validation
- Services: Business logic and data processing
- Models: Database schemas and data models
- Routes: API endpoint definitions
- Utils: Shared helper functions
- Create Route: Add route definition in
src/routes/ - Add Controller: Implement request handling in
src/controllers/ - Business Logic: Add service layer in
src/services/ - Database Model: Create/update Mongoose models in
src/models/ - Tests: Write unit tests for the new functionality
| Variable | Description | Default |
|---|---|---|
PORT |
Server port | 5000 |
JWT_SECRET |
JWT signing secret | supersecretkey |
DB_URI |
MongoDB connection string | mongodb://mongo:27017/nodeapp |
# Start all services
docker-compose up --build
# View logs
docker-compose logs -f api
# Stop services
docker-compose down
# Remove volumes (reset database)
docker-compose down -v# Build production image
docker build -t node-and-express .
# Run production container
docker run -p 5000:5000 --env-file .env node-and-express# Run all tests
yarn test
# Run tests in watch mode
yarn test --watch
# Run tests with coverage
yarn test --coverageThe development script automatically kills any process using port 5000 before starting.
- Ensure MongoDB is running (Docker or local installation)
- Check the
DB_URIin your.envfile - For Docker: ensure the mongodb service is running
# Check TypeScript configuration
npx tsc --noEmit
# Rebuild node_modules if needed
rm -rf node_modules yarn.lock
yarn install- Follow the existing code style and architecture
- Add tests for new features
- Update documentation as needed
- Ensure all linting and formatting checks pass
- Test with both Docker and local development setups
This project is licensed under the MIT License - see the LICENSE file for details. 5. For authentication, use JWT helpers in src/utils/jwt.ts. 6. Write corresponding tests in tests/.