TEN Stack: Typescript-Express-Node template (Updated 2022)

Filoscoder
aaant
Published in
2 min readAug 17, 2021

--

Overview

TEN stack is a Typescript + Express + Node starter-kit to develop a REST API server app.
Nothing new under the sun, just a straightforward combo to make server development a little bit faster. This template is perfect for anyone who is starting on the server-side world based on Node.js

This template comes with (UPDATED — 2022):

  • Class-based OOP architecture with DI & DAO
  • Equipped for TDD with Jest
  • Everything strictly typed with Typescript
  • ES6 features/modules
  • ES7 async / await
  • Global error handling architecture with templates (ApiError, TimeOutError, ValidationError, etc)
  • Request validators as custom middleware with Express-validator
  • Blazing fast logging with Express-Pinno-Logger
  • Run with Nodemon for automatic reload & watch
  • ESLint for code linting
  • Code formatting using Prettier
  • Configuration management using dotenv
  • Improved commits with Husky (v8) — pre-commit & pre-push
  • Manage production app process with PM2
  • CI/CD workflows with Github Actions
  • Editable Github Pull requests & Issue templates

Prerequisites

Install

  • Fork or Use this template repository.
  • Clone the forked repository.
  • Install the dependencies with yarn or npm.
  • Set your git remote path
git remote add origin ${forked-and-cloned-path}

Update the url if you already have an origin

Config

  • Copy .env.example a file at the root of the application.
  • Add or modify specific variables and update them according to your need.
 cp .env.example .env

Check the config folder to customize your settings (`/src/config`)

Alias @

To make paths clean and easy to access `@` is setup up for `/src` path

// BEFORE
import config from ‘./config’;
import routes from ‘./routes’;
// NOW
import config from ‘@/config’;
import routes from ‘@/routes’;

You can customize this setup in:
`/tsconfig.json` > compilerOptions.baseUrl & compilerOptions.paths

Local Development

Run the server locally. It will be run with Nodemon and ready to serve on port 8080 (unless you specify it on your .env)

 yarn start # or npm start

Check package.json to see more “scripts”

Continuous Integration & Continuous Deploy (CI/CD)

The workflows are under the .github folder

  • CI will be triggered on every PR update
  • CD will be triggered when specified branches got pushed (ex. main , develop)

If need more info about the setting, check this article

Production

First, build the application.

yarn build # or npm run build

Then, use pm2 to start the application as a service.

yarn service:start # or npm run service:start

Contribution

Check the source here. Please feel free to suggest changes or additions.

--

--