Setting Up an Express TypeScript Server: A Complete Guide (2026)
Learn how to build an Express.js server with TypeScript from scratch. This step-by-step guide covers installation, configuration, project structure, development scripts, and production builds.

If you're starting backend development with Node.js, one of the best combinations you can learn is Express.js and TypeScript. Express is one of the most popular web frameworks for Node.js because of its simplicity and flexibility, while TypeScript adds static typing, better tooling, and improved code quality.
Whether you're building a REST API, authentication service, SaaS product, or enterprise backend, setting up Express with TypeScript gives you a scalable and maintainable foundation.
In this guide, we'll build an Express TypeScript server from scratch using modern best practices.
Why Use TypeScript with Express?
JavaScript is incredibly powerful, but as applications grow, maintaining them becomes increasingly difficult. TypeScript solves many of these challenges by adding a strong type system on top of JavaScript.
Some major benefits include:
- Static type checking
- Better IntelliSense and auto-completion
- Easier refactoring
- Improved code maintainability
- Fewer runtime bugs
- Better collaboration for teams
Today, TypeScript has become the standard choice for professional Node.js development.
Prerequisites
Before starting, make sure you have:
- Node.js (v18 or later recommended)
- npm
- A code editor such as Visual Studio Code
- Basic understanding of JavaScript
- Basic knowledge of Express.js
You can verify your installation by running:
node -v
npm -v
Step 1: Create a New Project
Create a new project folder and initialize a Node.js application.
mkdir express-typescript-server
cd express-typescript-server
npm init -y
This generates a new package.json with default settings.
Step 2: Install Dependencies
Install Express.
npm install express
Now install the development dependencies.
npm install --save-dev typescript ts-node nodemon @types/node @types/express
Understanding Each Package
express
The lightweight web framework used to create APIs and web servers.
typescript
The TypeScript compiler that converts TypeScript into JavaScript.
ts-node
Allows you to execute TypeScript files directly without compiling first.
nodemon
Automatically restarts your development server whenever files change.
@types/node
Provides TypeScript definitions for Node.js APIs.
@types/express
Provides TypeScript definitions for Express.
Step 3: Configure TypeScript
Generate a TypeScript configuration file.
npx tsc --init
Replace the generated configuration with the following:
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./dist",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
What These Options Mean
- target specifies which JavaScript version TypeScript compiles to.
- module uses CommonJS modules, which are supported by Node.js.
- rootDir keeps all source files inside the
srcfolder. - outDir outputs compiled JavaScript into the
distfolder. - strict enables strict type checking.
- esModuleInterop allows cleaner imports from CommonJS packages.
Step 4: Create the Project Structure
Create the source directory.
mkdir src
touch src/server.ts
Your project should now look like this:
express-typescript-server
│
├── node_modules
├── src
│ └── server.ts
├── package.json
├── tsconfig.json
Keeping source code inside a dedicated src folder makes your application much easier to organize as it grows.
Step 5: Create the Express Server
Open src/server.ts and add the following code.
import express, { Application, Request, Response } from "express";
const app: Application = express();
const PORT = 3000;
// Parse JSON requests
app.use(express.json());
// Parse URL-encoded requests
app.use(express.urlencoded({ extended: true }));
// Home Route
app.get("/", (req: Request, res: Response) => {
res.send("Hello, TypeScript + Express!");
});
// Start Server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Code Breakdown
First, we import Express along with the TypeScript types for Application, Request, and Response.
Next, we create an Express application.
Then we register middleware to parse incoming JSON requests and URL-encoded form submissions.
After that, we define a simple GET route for the root endpoint.
Finally, we start the server and listen on port 3000.
Step 6: Configure package.json Scripts
Open your package.json and replace the scripts section with:
{
"scripts": {
"dev": "nodemon --exec ts-node src/server.ts",
"build": "tsc",
"start": "node dist/server.js"
}
}
Script Explanation
npm run dev
Starts the development server with automatic reloading.
npm run build
Compiles all TypeScript files into JavaScript.
npm start
Runs the compiled production build from the dist folder.
Step 7: Run the Development Server
Start the server.
npm run dev
If everything is configured correctly, you'll see:
Server is running on http://localhost:3000
Open your browser and visit:
http://localhost:3000
You should receive the following response:
Hello, TypeScript + Express!
Congratulations! Your Express TypeScript server is now running successfully.
Step 8: Build for Production
Before deploying your application, compile the TypeScript source code.
npm run build
A new dist directory will be generated containing the compiled JavaScript.
Run the production server:
npm start
Using compiled JavaScript in production results in faster startup times and avoids compiling TypeScript on every execution.
Recommended Project Structure
As your application grows, you'll likely organize it like this:
src
├── app.ts
├── server.ts
├── config
├── controllers
├── middleware
├── models
├── routes
├── services
├── interfaces
├── utils
└── types
Separating responsibilities into dedicated folders keeps your project clean, scalable, and easier to maintain.
Next Steps
Now that your server is running, consider adding:
- Express Router
- Environment variables with dotenv
- MongoDB or PostgreSQL
- Authentication using JWT
- Error handling middleware
- Request validation
- Logging
- ESLint and Prettier
- Docker support
- Unit testing with Jest or Vitest
These additions will transform this simple server into a production-ready backend.
Conclusion
Setting up Express with TypeScript is one of the best investments you can make as a backend developer. While the initial configuration takes a few extra minutes compared to plain JavaScript, the long-term benefits are significant. You'll write safer code, catch bugs earlier, enjoy better editor support, and build applications that are easier to scale and maintain.
This setup serves as an excellent foundation for REST APIs, SaaS platforms, authentication systems, microservices, and enterprise applications. From here, you're ready to start building real-world backend projects with confidence.


