Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Node.js: Introduction, Environment Setup, and the REPL

Lesson 39 of 46 in the free Web Technologies notes on Siksha Sarovar, written by Rohit Jangra.

Node.js: Introduction, Environment Setup, and the REPL

What is Node.js?

Node.js is a JavaScript runtime built on Chrome's V8 engine that lets JavaScript run outside the browser — on a server. It is:

  • Single-threaded with an event loop for non-blocking, asynchronous I/O
  • Ideal for I/O-heavy applications: APIs, real-time apps, streaming
  • Not a language or framework — it's a runtime environment

Node.js vs Traditional Server-Side Models

FeatureNode.jsTraditional (e.g., Apache/PHP)
ConcurrencySingle thread, event loopOne thread/process per request
I/O modelNon-blocking (async)Blocking (sync)
LanguageJavaScript everywhere (client + server)Different language per tier
Best forReal-time apps, APIs, streamingCPU-heavy, traditional web apps

Environment Setup

  1. Download the installer from nodejs.org (LTS version recommended)
  2. Verify installation:
node -v      # e.g., v20.11.0
npm -v       # e.g., 10.2.4
  1. Run a JavaScript file with Node:
node app.js

The REPL (Read-Eval-Print Loop)

Typing node with no arguments starts the REPL — an interactive shell for running JavaScript line by line, useful for quick testing.

$ node
> 2 + 3
5
> const greet = name => `Hello, ${name}!`;
undefined
> greet("World")
'Hello, World!'
> .exit

Useful REPL Commands

CommandPurpose
.helpList all REPL commands
.exit (or Ctrl+C twice)Exit the REPL
.editorEnter multi-line editing mode
.clearReset the REPL context
_Holds the result of the last expression

First Node.js Program

// hello.js
console.log("Hello, Node.js!");

const os = require('os');
console.log("Platform:", os.platform());
console.log("CPU cores:", os.cpus().length);
node hello.js

NPM (Node Package Manager)

NPM installs and manages third-party packages and is bundled with Node.js.

npm init -y                  # Create package.json with defaults
npm install express          # Install a package (saved as a dependency)
npm install --save-dev nodemon  # Install as a dev-only dependency
npm install                  # Install all dependencies listed in package.json
npm uninstall express        # Remove a package
npm list                     # List installed packages
npm outdated                 # Check for newer versions

package.json

{
  "name": "my-app",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "nodemon": "^3.0.1"
  }
}
Key Takeaway: Node.js runs JavaScript on the server using V8 and a non-blocking event loop, making it ideal for I/O-heavy applications. The REPL is great for quick experiments, and NPM (with package.json) manages your project's dependencies.