Boilerplate using Express + Typescript

A Web Server Built With Express, Typescript, Mongoose & Pug

Author

Faiz Ahmed Farooqui
Faiz Ahmed FarooquiPrincipal Technical Consultant.

Date

Oct 29, 2019

In ExpressJS, you always have to start with scratch for things like CSRF / JWT Token, Exception Handling, Clusters, Queues, Cache, etc. So, we thought to make is simple for everyone by building a boilerplate using Typescript to start off with.

The repository is available at GeekyAnt's GitHub under the name Express-Typescript.

Why we need this Boilerplate?

1. Exception Handling

Rather than restarting the entire node app repeatedly for minor bugs, we found a way to handle exceptions & errors using Nodes' process events.

2. Fork a New Cluster on Exit of Old Cluster

GeekyAnts' Express TypeScript: Cluster

Rather than sending the entire load onto a single Core / CPU, we try to take advantage of a multi-core system to handle load. Here, if the cluster dies for some reason, we create / fork a new one immediately.

3. Auth (using Email OR Social Accounts)

Using PassportJS as an interface, we keep adding configurations & registering them in the app for social authentication.

4. Logger

A Single Log class with methods like infowarnerror & custom. These methods send the log string to a file under <YYYY-MM-DD>.log directory of your project root and keep creating these log files on a daily basis rather than having a single log file. 

5. DotEnv

Use of .env, to load environment variables/constants for the entire app. So now, we have a single centralized constants location.

6. Tokens

We prefer using CSRF token for our Web routes and JWT token for API routes. So, we create middlewares for both tokens and register them against Web and API routes respectively.

7. Structure

There was a bit of a discussion on the issue of structuring of folders/files in ExpressJS. It was hard to establish where to organize and which files to organize, or if a perfect structure even existed and was possible to achieve.

At last, I came up with the following folder structure.

GeekyAnts' Express TypeScript: Structure

Note: This structure contains just parent folders.

8. Queues

There are various things in a backend logic that does not really need to happen upon a request like sending out E-Mails or SMS texts, etc. In short, things which require a connection to any third party service are overhead in some conditions

To fix this, I have used KueJS, a priority based job queue that runs on a Redis driver.

9. Cache

For caching of web routes, I have used a simple in-memory cache using memory-cache.

And many more features that you can read about and explore at GeekyAnts' Express TypeScript

Book a Discovery Call

Recaptcha Failed.

Related Articles.

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

How We Built an AI System That Automates Senior Solution Architect Workflows
Article

Apr 6, 2026

How We Built an AI System That Automates Senior Solution Architect Workflows

Discover how we built a 4-agent AI co-pilot that converts complex RFPs into draft technical proposals in 15 minutes — with built-in conflict detection, assumption surfacing, and confidence scoring.

AI Code Healer for Fixing Broken CI/CD Builds Fast
Article

Apr 6, 2026

AI Code Healer for Fixing Broken CI/CD Builds Fast

A deep dive into how GeekyAnts built an AI-powered Code Healer that analyzes CI/CD failures, summarizes logs, and generates code-level fixes to keep development moving.

A Real-Time AI Fraud Decision Engine Under 50ms
Article

Apr 2, 2026

A Real-Time AI Fraud Decision Engine Under 50ms

A deep dive into how GeekyAnts built a real-time AI fraud detection system that evaluates transactions in milliseconds using a hybrid multi-agent approach.

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms
Article

Apr 1, 2026

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms

GeekyAnts built a 5-agent fraud detection pipeline that makes decisions in under 200ms — 15x cheaper than single-model systems, with full explainability built in.

Building a Self-Healing CI/CD System with an AI Agent
Article

Mar 31, 2026

Building a Self-Healing CI/CD System with an AI Agent

When code breaks a pipeline, developers have to stop working and figure out why. This blog shows how an AI agent reads the error, finds the fix, and submits it for review all on its own.

Maestro Automation Framework — Advanced to Expert
Article

Mar 26, 2026

Maestro Automation Framework — Advanced to Expert

Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.

Scroll for more
View all articles