A clear guide to setting up a monolithic backend using Express, TypeScript, Yarn, and modern tooling.
Build a Simple Monolith Backend with Node.js and TypeScript
Many developers jump straight into microservices, even when it's not needed. For small teams or early-stage products, a monolith is often the better choice.
This post will walk you through building a monolith backend that is easy to understand, maintain, and ready for production. We use:
- Node.js + TypeScript
- Express
- Yarn
- ESLint + Prettier
- Jest for testing
- Husky + Commitlint
- GitHub Actions for CI
Why Monolith?
Here are a few reasons to start with a monolith:
- Simpler to build and debug — everything is in one place.
- Faster to develop — no need to set up multiple repos or services.
- Easier to refactor later into microservices when needed.
Tools We Use
Tool | What it does |
---|---|
Express.js | Handles routes and middleware |
TypeScript | Adds type safety and better tooling |
ESLint + Prettier | Makes your code clean and consistent |
Jest | For running tests |
Husky + Commitlint | Ensures good commits and quality |
Yarn | Dependency manager |
Folder Structure
Here’s how the project is organized:
src/
├── app.ts # Setup express and middleware
├── server.ts # Start the server
├── routes/ # Define routes
├── controllers/ # Request handlers
├── services/ # Business logic
├── middleware/ # Error & security middleware
├── config/ # Environment setup
└── utils/ # Helper functions
Setup in 5 Steps
git clone https://github.com/jonilabss/boelpart-nodejs-monolith-ts.git
cd boelpart-nodejs-monolith-ts
yarn install
yarn dev
Your server will run at http://localhost:3000
.
Running Tests
We use Jest for testing:
yarn test
yarn test:coverage
The goal is to keep test coverage as close to 100% as possible.
Git & CI Workflow
We use Husky, Lint-Staged, and Commitlint to make sure every commit is clean.
- Only allow commits that follow Conventional Commits
- Lint and test before commit and push
- CI with GitHub Actions runs on every pull request
CI config is in .github/workflows/ci.yml
.
Deployment
You can deploy this project on:
- Railway, Render, Vercel (for serverless)
- Docker
- PM2 (on your own VPS)
To build and start:
yarn build
yarn start
Final Thoughts
Monoliths are still useful, especially if you use the right tools. This setup gives you a strong foundation and makes it easier to move to microservices in the future if needed.
References
Want examples like login features, global error handlers, or DB integration (MongoDB, PostgreSQL)?
Check out the GitHub repo.
Top comments (0)