Boilerplate using Express + Typescript

Oct 14, 2019

Boilerplate using Express + Typescript

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

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 info, warn, error & 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

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization
Sep 23, 2026

Why Legacy Systems Make Business Growth More Expensive: Navigate A Smarter Path to Legacy Modernization

Learn how legacy systems make business growth more expensive and how edge-first modernization can remove constraints without replacing the existing system.

Insight
SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam
Sep 23, 2026

SSO, Audit Logs and RBAC: The Enterprise Features AI Prototyping Tools Do Not Cover | Sarika Gautam

Why AI-generated prototypes fail enterprise review: the context behind SSO, the cost of skipping audit logs, and how role explosion makes RBAC a product of its own.

Insight
Feature Flags as Technical Debt: The Cleanup Nobody Schedules
Sep 21, 2026

Feature Flags as Technical Debt: The Cleanup Nobody Schedules

This blog explains how unmanaged feature flags create technical debt and how teams can detect, manage, and remove them safely.

Insight
Building AI-First Enterprises: Why System Design Matters More Than AI Adoption
Sep 21, 2026

Building AI-First Enterprises: Why System Design Matters More Than AI Adoption

This blog explores how system design, architecture, and validation shape AI-first enterprises, while examining AIโ€™s impact on software engineering and human decision-making.

Insight
The Product Studio in the AI Era: What Actually Changes | Sarika Gautam
Sep 21, 2026

The Product Studio in the AI Era: What Actually Changes | Sarika Gautam

What changes in product development when AI writes the code: the shift to architecture, the token cost of unplanned builds, and why juniors still matter.

Insight
AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity
Sep 18, 2026

AI and the Future of Digital Customer Experience: Where Technology Meets Human Creativity

A discussion on how AI, human creativity, research, and cross-functional collaboration are shaping the future of digital customer experience.

Insight
Scaling Down Before Scaling Up: Why Bigger Servers Donโ€™t Fix Bad Architecture
Sep 17, 2026

Scaling Down Before Scaling Up: Why Bigger Servers Donโ€™t Fix Bad Architecture

This blog explores how inefficient backend architecture can cause performance issues even under low traffic, covering practical ways to reduce database load, API latency, and resource usage before scaling infrastructure.

Footer

The Right Conversation Can

Save You Six Months.

Book a Call