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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Node.js Basics with TypeScript | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 34 of 56

·Typescript

Node.js Basics with TypeScript

20 minutes

Course progress61%

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.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonRxJS TypingContinue to lesson 35Express Server Typed with TypeScriptBack to TypeScript Mastery curriculum