Express.js API Template
This is a starter Express.js1 API Template, helping to get past the routine of starting a new project from scratch again and again!
This template is still in WIP phase!
Table of Contents
- Prerequisites
- Usage
- Build
- Test
- Code Style
- Documents
- API
- Code
- Config
- Common
- Server
- Database
- Sentry
- Start
- Docker2
- Directory Layout
- Versioning
Prerequisites
- Node.js3 (
v16.13.2or higher) - MongoDB4 (
v5)
Usage
First install the dependencies:
Build
Build the project. (Using TypeScript5)
Watch for changes and rebuild automatically.
Test
Test the project. (Using Jest6)
Test with code coverage report.
Test in ci.
Code Style
Check for code style issues in the project. (Using ESLint7)
Fix code style issues in the project.
Documents
API Documents
Generate the API documents to be served statically. (Using Swagger8)
Generate & serve the API documents. (The documents' server address will be printed in the terminal)
Code Documents
Generate the Code documents to be served statically. (Using TypeDoc9)
After running this command, open docs/code/index.html in your preferred browser.
Config
First create the .env file:
Common Config
| Name | Type | Default | Description |
|---|---|---|---|
NODE_ENV |
production,development,test |
development |
Node.js3 environment (test will be provided by the testing framework automatically) |
RELEASE_ENV |
production,staging |
staging |
Release environment |
Server Config
| Name | Type | Default | Description |
|---|---|---|---|
SERVER_HOSTNAME |
string | localhost |
Express.js1 server hostname |
SERVER_PORT |
integer | 3000 |
Express.js1 server port |
Database Config
| Name | Type | Default | Description |
|---|---|---|---|
DATABASE_URI |
string | - | MongoDB4 connection string uri |
Sentry Config
| Name | Type | Default | Description |
|---|---|---|---|
SENTRY_DSN |
string | - | Sentry10 project DSN value |
Start
Start the API.
Watch for changes and restart automatically.
Docker
Start the services:
Stop the services:
Directory Layout
.
+-- __tests__ # Test files
| +-- controllers # Express.js controller tests
| +-- jest # Test utilities
+-- docs # Static documents
| +-- api # API documents
| +-- code # Code documents
+-- scripts # Project scripts
+-- src # Source files
+-- config # Configuration values
+-- constants # Constants
+-- controllers # Express.js controllers
+-- lib # Libraries
+-- models # Database models
Versioning
We use SemVer11 for versioning. For the versions & changelogs available, see the releases on this repository.