This repository serves as a boilerplate for setting up an Express server with TypeScript. It includes essential middleware and tools for building a robust and maintainable server application.
Install the dependencies:
npm install
To start the server in development mode, which uses nodemon
for auto-reloading:
-
Single instance:
npm run dev
-
Cluster mode:
npm run dev:cluster
To build and start the server for production:
-
Build the project:
npm run build
-
Start the server:
npm start
-
Start the server in cluster mode:
npm run start:cluster
The application requires the following environment variables, which should be defined in a .env
file:
Variable | Description | Default Value |
---|---|---|
APP_NAME |
Name of the application | boilerplate-express-server |
APP_SCHEMA |
Application schema (http/https) | http |
APP_HOSTNAME |
Hostname of the application | localhost |
APP_PORT |
Port number the app will listen on | 3000 |
APP_ROUTE_PREFIX |
Route prefix for the API | /api |
APP_COOKIE_SIGN_SECRET |
Secret for signing cookies | secret |
CLUSTER_NUMBER_OF_INSTANCES |
Number of cluster instances | 1 |
LOG_LEVEL |
Level of logging | info |
LOG_PATH |
Path to log files | (empty) |
Package | Description |
---|---|
@godaddy/terminus |
Graceful shutdown for your HTTP server. |
cookie-parser |
Parse Cookie header and populate req.cookies . |
cors |
Enable Cross-Origin Resource Sharing (CORS). |
dotenv |
Loads environment variables from a .env file. |
express-prom-bundle |
Prometheus middleware for Express. |
express-rate-limit |
Basic IP rate-limiting middleware. |
helmet |
Helps secure Express apps by setting various HTTP headers. |
http-status |
Utility to interact with HTTP status codes. |
pino |
Super fast, low overhead logging library. |
pino-http |
HTTP logger for Express. |
pino-pretty |
Pretty print logs for Pino. |
prom-client |
Prometheus client for Node.js. |
request-ip |
Middleware for getting a user's IP address. |
swagger-jsdoc |
Generates swagger spec from JSDoc comments. |
swagger-ui-express |
Serve swagger-ui for your API docs. |
This project is licensed under the MIT License. See the LICENSE file for more details.
Feel free to contribute to this repository by opening issues or submitting pull requests. Happy coding!