Node.js Introduction
Node.js runs JavaScript outside the browser - on your computer or on a server. With it you can build websites' back ends (APIs), command-line tools and scripts. It's fast at handling many users at once, which is why companies like Netflix, PayPal and Flipkart use it.
Before Node.js, JavaScript ran only inside browsers, and servers were written in other languages. Node let developers use one language for both the website and the server, and its non-blocking design handles thousands of connections efficiently. Today it powers APIs, real-time chat, build tools and command-line programs.
Install and check
Download the LTS version from nodejs.org. It also installs npm, the package manager.
node --version
# v22.12.0
npm --version
# 10.9.0Your first script
Save this as hello.mjs and run node hello.mjs. (The .mjs ending lets you use modern import - more in the next lesson.)
What's different from the browser?
- No
documentorwindow- there's no web page - You can read and write files, start servers and talk to databases
processtells you about the running program (arguments, environment, exit)
node on its own opens the REPL: type JavaScript and see the result straight away. Press Ctrl+C twice to leave.- Node.js runs JavaScript outside the browser.
- It's great for APIs, tools and real-time apps.
- There is no document or window; there is process.
