# Node.js Runtime Essentials

> Run JavaScript and TypeScript on the server, use core modules, manage configuration and understand what blocks the event loop. Free notes, key concepts,...

Canonical: https://www.internhack.in/roadmaps/tracks/full-stack/nodejs-runtime
Last updated: 2026-11-28

Run JavaScript and TypeScript on the server, use core modules, manage configuration and understand what blocks the event loop.

Intermediate · about 6 hours · difficulty 2/5

Learn first: [Asynchronous JavaScript and fetch](https://www.internhack.in/roadmaps/tracks/full-stack/async-javascript), [TypeScript Fundamentals](https://www.internhack.in/roadmaps/tracks/full-stack/typescript), [HTTP, Requests and Responses](https://www.internhack.in/roadmaps/tracks/full-stack/http-basics)

Node.js runs JavaScript outside the browser. It powers Express, Fastify and the server side of Next.js, so its behaviour is your backend's behaviour.

### Essentials

- Run scripts with node, and TypeScript in development with tsx. Use the current **LTS** version.
- Core modules: fs/promises for files, path, crypto for hashing and random tokens, and the built-in fetch.
- **process.env** for configuration, loaded from .env files in development and from the platform in production.
- ES modules vs CommonJS: prefer ESM ("type": "module") for new projects, but recognise require() in older code.

### Performance model

Node handles many concurrent requests on one thread because I/O is non-blocking. CPU-heavy work (resizing images, generating large PDFs, hashing with high cost in a loop) blocks every other request. Move such work to a background job or a worker thread.

### Reliability

- Handle unhandledRejection and uncaughtException by logging and exiting; let the platform restart the process.
- Implement **graceful shutdown**: on SIGTERM, stop accepting requests, finish in-flight ones, close the database pool.
- Use a file watcher (node --watch or tsx watch) in development.

### Pitfalls

- Synchronous fs calls inside request handlers.
- Reading process.env all over the codebase instead of validating it once at startup.
- Running an odd-numbered or end-of-life Node version in production.

You are ready to move on when you can write a small Node.js HTTP server with the built-in http module, read config from validated env vars, and shut it down gracefully.

## Key concepts

- **LTS versions and nvm**
- **Core modules: fs, path, crypto**
- **process.env and .env files**
- **ESM vs CommonJS**
- **Blocking vs non-blocking work**
- **Graceful shutdown**
- **Running TypeScript with tsx**
- **Worker threads**

## Mini project

Build a tiny URL shortener using only Node's built-in http module and a JSON file for storage, with env-based config validated by Zod and graceful shutdown on SIGTERM.

## Check yourself

One endpoint generates a large PDF synchronously and the whole API becomes slow for everyone. Why, and what are two fixes?

## Free resources

- [Learn Node.js](https://nodejs.org/en/learn) (Node.js)
- [Node.js API Documentation](https://nodejs.org/docs/latest/api/) (Node.js)
- [Node.js Roadmap](https://roadmap.sh/nodejs) (roadmap.sh)

Previous: [Rendering Strategies, Metadata and SEO](https://www.internhack.in/roadmaps/tracks/full-stack/rendering-and-seo) · Next: [REST API Design](https://www.internhack.in/roadmaps/tracks/full-stack/rest-api-design)

## More in Node.js and API Design

- [Node.js Runtime Essentials](https://www.internhack.in/roadmaps/tracks/full-stack/nodejs-runtime)
- [REST API Design](https://www.internhack.in/roadmaps/tracks/full-stack/rest-api-design)
- [Building APIs with Express](https://www.internhack.in/roadmaps/tracks/full-stack/express)
- [Building APIs with Fastify](https://www.internhack.in/roadmaps/tracks/full-stack/fastify)
- [API Routes with Next.js Route Handlers](https://www.internhack.in/roadmaps/tracks/full-stack/next-route-handlers)
- [Error Handling, Validation and API Hardening](https://www.internhack.in/roadmaps/tracks/full-stack/api-errors-and-validation)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Full-Stack Developer Roadmap](https://www.internhack.in/roadmaps/tracks/full-stack)
