Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 34 of 56 · Typescript

Node.js Basics with TypeScript

Duration: 20 minutes

Initialize a Node TS project

mkdir ts‑node && cd $_
npm init -y
npm i -D typescript @types/node
npx tsc --init

Modify tsconfig.json to target CommonJS.

"module": "CommonJS",
"outDir": "dist",

Simple HTTP server with http

import http from 'http';

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello from TypeScript Node!');
});

server.listen(3000, () => console.log('🟢 listening on 3000'));

Run with npx ts-node src/server.ts or compile with tsc then node dist/server.js.

Using process.env with typings

const PORT = Number(process.env.PORT ?? 3000);

Info

Enable esModuleInterop in tsconfig to import CommonJS modules with import foo from 'foo' syntax.

Previous: RxJS TypingNext: Express Server Typed with TypeScript