← Learning Hub
Beginner

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.

Example
node --version
# v22.12.0
npm --version
# 10.9.0

Your 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.)

Example
You can edit this code.

What's different from the browser?

  • No document or window - there's no web page
  • You can read and write files, start servers and talk to databases
  • process tells you about the running program (arguments, environment, exit)
Example
You can edit this code.
Typing node on its own opens the REPL: type JavaScript and see the result straight away. Press Ctrl+C twice to leave.
Key points
  • 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.

📝 Test yourself

1. What is Node.js?
2. Which of these is NOT available in Node.js?
3. Fill in the command that runs a file:
hello.mjs