Skip to content

This is a starter Express.js API Template, helping to get past the routine of starting a new project from scratch again and again!

License

Notifications You must be signed in to change notification settings

ardalanamini/express-api-template

Repository files navigation

Express.js API Template

Test CodeCov

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

  • Node.js3 (v16.13.2 or higher)
  • MongoDB4 (v5)

Usage

First install the dependencies:

npm i

Build

Build the project. (Using TypeScript5)

npm run build

Watch for changes and rebuild automatically.

npm run build:watch

Test

Test the project. (Using Jest6)

npm test

Test with code coverage report.

npm run test:coverage

Test in ci.

npm run test:ci

Code Style

Check for code style issues in the project. (Using ESLint7)

npm run lint

Fix code style issues in the project.

npm run lint:fix

Documents

API Documents

Generate the API documents to be served statically. (Using Swagger8)

npm run docs:swagger

Generate & serve the API documents. (The documents' server address will be printed in the terminal)

npm run docs:api

Code Documents

Generate the Code documents to be served statically. (Using TypeDoc9)

npm run docs:code

After running this command, open docs/code/index.html in your preferred browser.

Config

First create the .env file:

cp .env.example .env

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.

npm start

Watch for changes and restart automatically.

npm run start:watch

Docker

Start the services:

docker-compose up -d --build --remove-orphans

Stop the services:

docker-compose down

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.

Footnotes

  1. Express.js 2 3

  2. Docker

  3. Node.js 2

  4. MongoDB 2

  5. TypeScript

  6. Jest

  7. ESLint

  8. Swagger

  9. TypeDoc

  10. Sentry

  11. SemVer