1. Home
  2. Coding Hub
  3. Coding Notes
  4. Nodejs
  5. Introduction
45% OFFBLACK FRIDAY SALE
Sale ends in
03Days
01Hrs
11Mins
50Secs
Claim
  1. Home
  2. Coding Hub
  3. Coding Notes
  4. Nodejs
  5. Introduction

Limited time offer

45% OFF

BLACK FRIDAY SALE

Sale ends in

03Days
01Hrs
11Mins
50Secs
Claim
HTMLCSSJavaScriptPythonJavaC++React.jsSQLNext.jsNode.js
Underrated CoderUnderrated Coder
Underrated CoderUnderrated Coder
Resources
  • Coding Hub
  • Roadmap
  • DSA Sheet
  • Coding Notes
  • Coding Quiz
  • Code Compiler
  • Coder AI
Interview Preparation
  • 1:1 Mentorship
  • Interview Q&A
Community
  • Blog
  • Coder Community
Help & Support
  • Contact Us
  • Troubleshooting
  • Report a Bug
HTMLCSSJavaScriptPythonJavaC++React.jsSQLNext.jsNode.js
Outline
Node.js IntroductionV8 & libuvEvent Loop PhasesnextTick vs setImmediateCommonJS vs ESMNPM & package.json
process & GlobalsNative Env Variablespath & osBlocking vs Non-Blockingfs/promises APIEventEmitter Architecture
Binary BuffersReadable & Writable StreamsDuplex & Transform StreamsStream pipeline()Stream Backpressure
Native http ServerRequest & ResponseExpress.js SetupRouting & ParametersMiddleware PipelineRequest Body ParsingGlobal Error Handling
RESTful API DesignHTTP Status CodesInput ValidationPassword HashingJWT AuthenticationHTTP-Only CookiesCORS & HelmetAPI Rate Limiting
File UploadsDatabase Connection PoolingIn-Memory CachingWebSockets & Socket.io
Child ProcessesWorker ThreadsCluster ModuleGraceful Shutdown
Node.js

Node.js Introduction

Overview

Historically, JavaScript was trapped inside the web browser, only capable of manipulating the DOM or showing alerts. In 2009, Ryan Dahl ripped the V8 JavaScript Engine out of Google Chrome, bolted it to a C++ library, and called it Node.js. Node.js is NOT a framework or a language; it is a Runtime Environment. It allows JavaScript to run directly on the Operating System (servers), giving it the power to read files, connect to databases, and handle network traffic, making JS a full-stack language.

Syntax

javascript
// 1. You no longer have access to Browser APIs!
// console.log(window); // FATAL ERROR: window is not defined
// console.log(document); // FATAL ERROR: document is not defined

// 2. You DO have access to OS-level APIs!
const os = require('os');
console.log(os.platform()); // 'darwin' (macOS), 'win32' (Windows), 'linux'
console.log(os.cpus().length); // Prints how many CPU cores your server has!

// 3. Executing a Node script from the terminal:
// $ node server.js

Common Pitfalls

  • Assuming Node.js is a 'Backend Framework'. Node.js is just the engine (like the JVM for Java or the Python Interpreter). Express.js or NestJS are the actual frameworks built on top of Node.js.
  • Trying to use alert() or localStorage in a Node script. Because there is no Chrome browser rendering a GUI, these global browser objects literally do not exist in the Node runtime.

Interview Questions

Is Node.js single-threaded or multi-threaded?

Node.js is 'Single-Threaded' when executing your JavaScript code. However, under the hood, the C++ libraries it relies on (like libuv) manage a hidden multi-threaded Thread Pool (usually 4 threads) to offload heavy OS tasks like File I/O and Cryptography, preventing the main JS thread from blocking.

Real-World Example

Writing a simple server that returns 'Hello World' using raw Node.js.

example
javascript
// This is built directly into Node! No npm installs needed.
const http = require('http');

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

server.listen(3000, () => console.log('Server is alive!'));

Check Your Knowledge

Test your understanding of Node.js Introduction with these quick questions.

Question 1

What exactly is Node.js technically defined as?

Take Node.js Quiz
Outline
Node.js IntroductionV8 & libuvEvent Loop PhasesnextTick vs setImmediateCommonJS vs ESMNPM & package.json
process & GlobalsNative Env Variablespath & osBlocking vs Non-Blockingfs/promises APIEventEmitter Architecture
Binary BuffersReadable & Writable StreamsDuplex & Transform StreamsStream pipeline()Stream Backpressure
Native http ServerRequest & ResponseExpress.js SetupRouting & ParametersMiddleware PipelineRequest Body ParsingGlobal Error Handling
RESTful API DesignHTTP Status CodesInput ValidationPassword HashingJWT AuthenticationHTTP-Only CookiesCORS & HelmetAPI Rate Limiting
File UploadsDatabase Connection PoolingIn-Memory CachingWebSockets & Socket.io
Child ProcessesWorker ThreadsCluster ModuleGraceful Shutdown
Node.js

Node.js Introduction

Overview

Historically, JavaScript was trapped inside the web browser, only capable of manipulating the DOM or showing alerts. In 2009, Ryan Dahl ripped the V8 JavaScript Engine out of Google Chrome, bolted it to a C++ library, and called it Node.js. Node.js is NOT a framework or a language; it is a Runtime Environment. It allows JavaScript to run directly on the Operating System (servers), giving it the power to read files, connect to databases, and handle network traffic, making JS a full-stack language.

Syntax

javascript
// 1. You no longer have access to Browser APIs!
// console.log(window); // FATAL ERROR: window is not defined
// console.log(document); // FATAL ERROR: document is not defined

// 2. You DO have access to OS-level APIs!
const os = require('os');
console.log(os.platform()); // 'darwin' (macOS), 'win32' (Windows), 'linux'
console.log(os.cpus().length); // Prints how many CPU cores your server has!

// 3. Executing a Node script from the terminal:
// $ node server.js

Common Pitfalls

  • Assuming Node.js is a 'Backend Framework'. Node.js is just the engine (like the JVM for Java or the Python Interpreter). Express.js or NestJS are the actual frameworks built on top of Node.js.
  • Trying to use alert() or localStorage in a Node script. Because there is no Chrome browser rendering a GUI, these global browser objects literally do not exist in the Node runtime.

Interview Questions

Is Node.js single-threaded or multi-threaded?

Node.js is 'Single-Threaded' when executing your JavaScript code. However, under the hood, the C++ libraries it relies on (like libuv) manage a hidden multi-threaded Thread Pool (usually 4 threads) to offload heavy OS tasks like File I/O and Cryptography, preventing the main JS thread from blocking.

Real-World Example

Writing a simple server that returns 'Hello World' using raw Node.js.

example
javascript
// This is built directly into Node! No npm installs needed.
const http = require('http');

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

server.listen(3000, () => console.log('Server is alive!'));

Check Your Knowledge

Test your understanding of Node.js Introduction with these quick questions.

Question 1

What exactly is Node.js technically defined as?

Take Node.js Quiz

Node.js coding notes for Indian students — 40 topics with syntax, pitfalls, interview Q&A, and inline quizzes.

Topics in Node.js

  1. Node.js Introduction
  2. V8 & libuv
  3. Event Loop Phases
  4. nextTick vs setImmediate
  5. CommonJS vs ESM
  6. NPM & package.json
  7. process & Globals
  8. Native Env Variables
  9. path & os
  10. Blocking vs Non-Blocking
  11. fs/promises API
  12. EventEmitter Architecture
  13. Binary Buffers
  14. Readable & Writable Streams
  15. Duplex & Transform Streams
  16. Stream pipeline()
  17. Stream Backpressure
  18. Native http Server
  19. Request & Response
  20. Express.js Setup
  21. Routing & Parameters
  22. Middleware Pipeline
  23. Request Body Parsing
  24. Global Error Handling
  25. RESTful API Design
  26. HTTP Status Codes
  27. Input Validation
  28. Password Hashing
  29. JWT Authentication
  30. HTTP-Only Cookies
  31. CORS & Helmet
  32. API Rate Limiting
  33. File Uploads
  34. Database Connection Pooling
  35. In-Memory Caching
  36. WebSockets & Socket.io
  37. Child Processes
  38. Worker Threads
  39. Cluster Module
  40. Graceful Shutdown

Study next

  • All coding notes
  • Node.js notes home
  • Node.js certification quiz
  • Online compiler
  • Interview Q&A

Node.js coding notes for Indian students — 40 topics with syntax, pitfalls, interview Q&A, and inline quizzes.

Topics in Node.js

  1. Node.js Introduction
  2. V8 & libuv
  3. Event Loop Phases
  4. nextTick vs setImmediate
  5. CommonJS vs ESM
  6. NPM & package.json
  7. process & Globals
  8. Native Env Variables
  9. path & os
  10. Blocking vs Non-Blocking
  11. fs/promises API
  12. EventEmitter Architecture
  13. Binary Buffers
  14. Readable & Writable Streams
  15. Duplex & Transform Streams
  16. Stream pipeline()
  17. Stream Backpressure
  18. Native http Server
  19. Request & Response
  20. Express.js Setup
  21. Routing & Parameters
  22. Middleware Pipeline
  23. Request Body Parsing
  24. Global Error Handling
  25. RESTful API Design
  26. HTTP Status Codes
  27. Input Validation
  28. Password Hashing
  29. JWT Authentication
  30. HTTP-Only Cookies
  31. CORS & Helmet
  32. API Rate Limiting
  33. File Uploads
  34. Database Connection Pooling
  35. In-Memory Caching
  36. WebSockets & Socket.io
  37. Child Processes
  38. Worker Threads
  39. Cluster Module
  40. Graceful Shutdown

Study next

  • All coding notes
  • Node.js notes home
  • Node.js certification quiz
  • Online compiler
  • Interview Q&A