Node Express TypeScript Starter is a boilerplate for building scalable applications with Node.js and Express. It includes essential packages like Axios, Mongoose, JWT, and testing support using Jest and Supertest. The project is also configured with ESLint and Prettier for consistent code quality.
- Project Overview
- Technologies Used
- Installation
- Environment Variables
- Project Structure
- Folder Descriptions
- Scripts
- Contributing
This project serves as a scalable starting point for building RESTful APIs with Node.js, Express, and TypeScript. It is ideal for rapid development of web services with essential security, logging, and testing features. The boilerplate includes support for user authentication, JWT tokens, and database connections with MongoDB and Redis.
- Node.js: Backend runtime environment.
- TypeScript: Strongly typed programming language for better maintainability.
- MongoDB: NoSQL database for data storage and management.
- Redis: In-memory data store used for caching and session management.
- Docker: Containerization platform for consistent deployments across environments.
- Jest: Testing framework for unit and integration tests.
- Morgan: HTTP request logger middleware for better monitoring.
- ESLint & Prettier: Code quality and formatting tools to maintain consistent code style.
- Clone the repository:
git clone <repository-url> cd <project-folder>
- Install dependencies:
npm install
- Create an
.env
file using.env.example
as a template:cp .env.example .env
- Run the application:
npm run watch
.vscode/
build/
coverage/
logs/
node_modules/
src/
tests/
Dockerfile
docker-compose.yml
package.json
README.md
Configuration files for Visual Studio Code (e.g., settings, launch configurations).
Compiled production build files (generated during build processes).
Coverage reports for testing.
Logs generated by the application (such as HTTP requests, errors, etc.).
Main application source code.
Application configuration files (e.g., config.ts
, logger.ts
, redisClient.ts
).
Global constants, such as messages or application-wide values.
Controllers handle HTTP requests and business logic for routes.
Database-related logic and initialization files (including Mongoose setup).
Utility functions like error handling, JWT helpers, and response formatting.
Custom middleware for authentication, error handling, rate limiting, and validation.
Database models and schema definitions.
Route handlers that define the API endpoints.
Business logic and service layers interacting with models and external services.
Validation schemas and logic for API request payloads.
app.ts
: Application entry point, including middleware and route registration.server.ts
: Server initialization and startup logic.
Unit and integration tests, along with test setup files.
Environment variable configurations.
ESLint configuration and ignored files.
Prettier configuration and ignored files.
Configuration file for Jest testing framework.
In the project directory, you can run the following scripts:
Build the project and then start the server.
npm run start
Clean previous builds and compile the TypeScript code.
npm run build
Run the compiled server using Node.js.
npm run serve
Run the TypeScript compiler and the Node.js server in "watch" mode, meaning it will automatically rebuild and reload the server whenever you change a file.
npm run watch
Run nodemon
on the built server files, allowing the server to restart automatically whenever a change is detected.
npm run watch-node
Clean the build
directory before rebuilding.
npm run clean
Compile the TypeScript files into JavaScript.
npm run build-ts
Run TypeScript's type checking without emitting compiled files.
npm run check
Run ESLint on all JavaScript and TypeScript files in the project.
npm run eslint
Run Jest for testing with coverage and verbose output.
npm run test
concurrently
: Runs multiple npm commands in parallel.nodemon
: Watches for file changes and restarts the server.eslint
: Ensures that the code follows the specified coding standards.jest
: Runs unit and integration tests.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - Open a Pull Request.