A boilerplate/template to kickstart a new Node.js project using TypeScript and Express with a sensible setup for development and production.
- TypeScript for static typing
- Express for HTTP server & routing
nodemon
+ts-node
for fast development (auto-reload)- Structured folder layout (
src
/dist
) - Source maps, declaration files
- Configuration for strict type checks,
esModuleInterop
, etc. - Built-in scripts for building, running in dev & production
- Node.js (preferably version 16 or newer)
- npm (comes bundled with Node)
-
Clone the repository
git clone https://github.com/raj248/nodejs-ts-template.git cd nodejs-ts-template
-
Install dependencies
npm install
-
Dev dependencies
These are already included, e.g.:
npm install --save-dev typescript ts-node @types/node @types/express nodemon
-
Configure TypeScript
There’s a
tsconfig.json
preconfigured. Key settings:module
: CommonJS (or you can switch to ES module if required)target
:esnext
rootDir
:./src
outDir
:./dist
- Strict type checking enabled
-
Scripts
The
package.json
scripts:"scripts": { "dev": "nodemon", "build": "tsc", "start": "node dist/index.js", "clean": "rimraf ./dist" }
npm run dev
→ Runs in development mode with auto-reloadnpm run build
→ Compiles.ts
to.js
intodist
npm start
→ Runs the compiled production codenpm clean
→ Removesdist
folder
- nodemon.json ‒ defines what files/folders to watch, and what extensions to trigger reloads
- tsconfig.json ‒ TypeScript compiler settings
.gitignore
‒ ignorenode_modules
,dist
,.env
etc..env
or.env.example
(if you include env variables) for configuration based on environment. Learn more- currenly using dotenvFlow for env variable
-
Dev mode
npm run dev
Works with live reloading.
-
Build for production
npm run build
-
Start production server
npm start
If you want to contribute:
- Fork the repo
- Create a branch like
feature/my-feature
orfix/bug-description
- Make your changes, ensure TypeScript compiles without errors
- Submit a Pull Request with a description of the changes
- This project is licensed under the MIT License.
- Thanks to Express for routing and server framework
- Thanks to TypeScript for type safety
- Thanks to tooling like nodemon & ts-node for improving dev workflow
nodejs-ts-template/
├── src/
│ ├── controllers/
│ ├── routes/
│ ├── middlewares/
│ ├── utils/
│ ├── index.ts
│ └── (other modules)
├── dist/ # compiled js output
├── .gitignore
├── nodemon.json
├── package.json
├── tsconfig.json
├── README.md
└── (optional) .env.example