Node.js TypeScript Project Setup for 2025
Hello, guy. Here is a simple and perfect setup for your new Node.js TypeScript project. Because I have also searched for this type of article, I can easily set up my project in minutes and start my main work. So, not wasting your time, let’s start
First start the project with this command
Then install express and and dev dependency
npm i express
npm i -D typescript ts-node-dev @types/node @types/express
These are the development dependencies, so don’t worry about this. It only makes the typescript work easily so that it can run without giving you any type errors.
not wasting your this, so this is the index.ts file, which is inside the src folder
import express, { Request, Response } from "express";
const app = express();
const PORT = process.env.PORT || 8000;
app.use(express.json());
app.get('/', (req: Request, res: Response) => {
res.send('Server Start')
})
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
To let the TypeScript compiler know how to handle your project, you can generate a tsconfig.json file by running npx tsc --init,
Then, update the tsconfig.json file with your project's settings, like include, exclude, compilerOptions, and more.
{
"compilerOptions": {
"target": "ES2024",
"module": "commonjs",
"rootDir": "./src",
"types": ["node","express"],
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
Update the package.json file
"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"build": "tsc",
"start": "node dist/index.js"
}
So this is the basic setup of NodeJS TypeScript project If you are working with Docker, then this file will help you, and update this file if any update you want
FROM node:22.15.1-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY tsconfig.json ./
COPY src ./src
RUN npm run build
FROM node:22.15.1-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --omit=dev
COPY --from=builder /app/dist ./dist
COPY .env ./
ENV NODE_ENV=production
ENV PORT=8000
EXPOSE 8000
CMD ["node", "dist/index.js"]
So that's all for this. If you have any other suggestions about the article on nodejs or in the backend then leave a comment