Concepts, working and Features; downloading Node.js

Node.js runs JavaScript outside the browser on Chrome's V8 engine: single-threaded, event-driven, non-blocking, and installed in 5 minutes from nodejs.org.

10 min read · 11 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

The box you never built

Every Unit 4 diagram had a box labelled server, quietly answering search.php and seats.json. You drew it; you never built it.

Building it traditionally meant a NEW language: PHP, Java, C#. A second syntax, second toolchain, second brain.

In 2009, Ryan Dahl asked the better question: the browser already runs JavaScript brilliantly: why can't the SERVER? He lifted Chrome's engine out of the browser, and Node.js was born. Your jQuery-and-AJAX JavaScript is about to switch sides.

Theory

Node.js, formally

Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome's V8 engine that executes JavaScript OUTSIDE the browser.

Unpack each phrase:

  • runtime, not a language: the language is still JavaScript; Node is the place it runs
  • V8: Chrome's engine, which compiles JS to machine code: Node inherits its speed
  • outside the browser: no DOM, no window: instead, files, networks, ports: server territory

One language, both sides of the wire: that is the headline.

Theory

The cashier who never waits

A traditional server is a canteen with one cashier per customer: order biryani (slow to cook), and YOUR cashier stands idle at the counter until it is ready. Crowds need armies of cashiers.

Node is one brilliant cashier: takes your order, hands it to the kitchen with a token, and serves the next person immediately. When the kitchen bell rings, your order is delivered. One thread, never waiting, thousands served: that bell-and-token system is the event loop.

Theory

Features (the exam list)

  • Asynchronous and event-driven: I/O never blocks; callbacks fire when work completes: the fadeOut/AJAX model, now running the whole server
  • Single-threaded, highly scalable: one event loop instead of a thread per client
  • Very fast: V8 compiles JavaScript to machine code
  • No buffering: data is processed in chunks as it arrives
  • npm: the world's largest package ecosystem, installed alongside Node
  • Open source and cross-platform: Windows, Linux, macOS

Follow along

Downloading and first run (Windows)

  1. Visit nodejs.org Two buttons: choose LTS (Long Term Support), the stable one recommended for most users.
  2. Run the installer Next-next-finish; it installs node AND npm, and adds both to your PATH.
  3. Verify in a command prompt node -v prints the Node version; npm -v prints npm's. Both answering = success.
  4. Run your first file Save JavaScript as app.js, then: node app.js. No browser anywhere in the loop.

Practical

app.js: JavaScript with no browser around it

// This is server-side JavaScript: same language, new home.
console.log("FestConnect server starting...");

const total = 350;
const booked = 310;
console.log("Seats left for Garba Night: " + (total - booked));

// Note what is MISSING here: no document, no window, no DOM.
// Node trades those for files, networks and ports (next lessons).

This example runs in Gri-Learn on the web, where you can edit it and see the output.

Quiz

What exactly is Node.js?

  1. A new server-side programming language similar to JavaScript
  2. A JavaScript runtime built on Chrome's V8 engine that runs JS outside the browser
  3. A browser designed for developers
  4. A JavaScript library, like jQuery, included with a script tag
Show the answer

A JavaScript runtime built on Chrome's V8 engine that runs JS outside the browser

Node is a RUNTIME: an environment where the same JavaScript language executes, minus the browser, plus server powers. Option A is the classic mislabel: no new language was invented; your Unit 2 and 4 syntax carries over untouched. Option C inverts it: Node removed the browser rather than being one. Option D confuses delivery: libraries load INTO pages via script tags; Node is installed on a machine and runs files from the command line: node app.js, no page anywhere.

Think first

One thread, ten thousand students?

Fest results night: 10000 students hit the server at once. Node has ONE thread. Before tapping: reason out why it does not collapse, using the cashier and what each request mostly consists of.

Show the answer

Because a web request is mostly WAITING: for a file to read, a database to answer, a network packet to crawl back: and Node never spends its thread on waiting. Each slow operation is handed off with a callback (the kitchen token); the loop instantly serves the next student; completions ring back in as events. Ten thousand mostly-waiting requests interleave beautifully through one never-idle thread. The honest footnote: heavy CALCULATION (not waiting) does block the single thread: Node's famous weakness, worth one exam line.

Watch out

First-week Node confusions

Expecting the DOM: document.getElementById does not exist here: no page is loaded. Node's objects are files, requests, responses.

node vs npm: node RUNS JavaScript; npm INSTALLS packages. Two tools, one installer.

"Single-threaded means weak": backwards for I/O work: the event loop is WHY Node scales: but write the calculation caveat for full marks.

Theory

The async model completes its trilogy

Count the appearances: jQuery effects (start the animation, callback when done), AJAX (send the request, handler when done), and now Node (start the I/O, callback when done). One mental model, three units: master it once, and this entire subject's hardest idea is a single idea. Next lesson the cashier opens shop: http.createServer, and localhost:8080 says hello.

Summary

Key takeaways

  • Node.js = open-source, cross-platform JavaScript RUNTIME on Chrome's V8: JS outside the browser.
  • One language, both sides: browser JS and server JS.
  • Working: single thread + event loop; I/O is handed off with callbacks, never waited on.
  • Features: async/event-driven, scalable single thread, V8 speed, no buffering, npm, cross-platform.
  • Install: nodejs.org LTS, verify with node -v and npm -v, run with node app.js.
  • No DOM on the server; heavy computation is the single thread's true weakness.
  • Memory hook: one cashier, kitchen tokens, nobody waits.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Node.js

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Concepts, working and Features; downloading Node.js · Web Designing-2 (option A) · Gri-Learn