Node Express Typescript setup

Published on January 3, 2023

Node Express typescript Setup

This project is a basic Node.js Express server using TypeScript. It includes Nodemon for development and TSX for faster TypeScript execution without needing a build step while developing.

Folder setup

mkdir server && cd server
npm init -y

Install Dependencies

npm install express

Dev Dependencies

npm i -D typescript @types/node @types/express nodemon tsx

Initialize TypeScript Create typeconfig.json file

npx tsc --init

nodemon.json

{
"watch": ["src"],
"ignore": ["src/**/*/.spec.ts"],
"ext": "ts,json",
"exec": "tsx --env-file=.env src/server.ts"
}

Note: tsx lets you run TS directly without compiling during development.

Scripts (package.json)

script : {
"dev": "nodemon",
"start": "node ./dist/src/server.js",
"build": "tsc"
}

| Feature | Tool | | ----------------- | ------------------------- | | Web Framework | Express | | Language | TypeScript | | Live Dev Reload | Nodemon | | Fast TS Execution | TSX | | Compile to JS | TypeScript Compiler (tsc) |