Introduction to Node.js

Node.js is a runtime that lets you run JavaScript outside the browser to build servers, command-line tools, and back-end applications.

Learn Introduction to Node.js in our free Node.js course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Node.js course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

By the end of this lesson you'll understand what Node.js is and why it exists, how it runs JavaScript without a browser, and you'll have written and run your own first Node script that prints to the terminal.

What You'll Learn in This Lesson

1️⃣ What is Node.js?

For years JavaScript could only run inside a web browser. In 2009 Node.js changed that by taking Chrome's JavaScript engine (called V8 ) and wrapping it so JavaScript could run anywhere — on servers, on your laptop, in scripts. It rests on a few key ideas:

Because of this, Node powers a huge amount of the modern web — APIs, build tools, and command-line apps. You'll start where every Node developer starts: a tiny script that prints text to the terminal. Read the worked example below first — every line is explained — then run it yourself.

2️⃣ Why Node.js? Runtime Info and Non-Blocking Code

Two things make Node feel different from browser JavaScript. First, Node gives you a global process object full of information about the running program — like the Node version and the operating system. Second, Node is non-blocking : code that has to wait gets scheduled and runs later, so your program never freezes while it waits. Read the comments, predict the order of the lines, then check.

Notice the surprise: even with a 0 ms delay, the setTimeout line printed last . Node didn't stop and wait — it scheduled that work and finished the rest of the script first. That scheduling-instead-of-waiting behavior is the heart of why Node handles so many connections efficiently.

Your turn. The script below works once you fill in the two blanks marked ___ . Follow the 👉 hints, then run it and compare with the expected output.

3️⃣ Running a File with the node Command

To run a Node script on your own machine, save it in a file ending in .js (for example hello.js ) and type node hello.js in your terminal. Node reads the file top to bottom and prints anything you console.log to the screen.

No blanks this time — just a brief and an outline to keep you on track. Write it yourself, run it with node info.js , and check your output against the example in the comments. This is exactly the kind of tiny program that builds real fluency.

📋 Quick Reference — Node.js Basics

Practice quiz

What exactly is Node.js?

  • A JavaScript framework
  • A runtime that runs JavaScript outside the browser
  • A new programming language
  • A web browser

Answer: A runtime that runs JavaScript outside the browser. Node.js is a runtime; the language is still plain JavaScript.

Which engine does Node.js use to run JavaScript?

  • SpiderMonkey
  • Chakra
  • V8 (the engine in Chrome)
  • Nashorn

Answer: V8 (the engine in Chrome). Node is built on Google's V8 engine, the same one inside Chrome.

How do you run a file named app.js with Node?

  • node app.js
  • run app.js
  • javascript app.js
  • node run app.js

Answer: node app.js. You execute a script by typing node followed by the filename.

Which command prints the installed Node.js version?

  • node version
  • node --show
  • node -v
  • node info

Answer: node -v. node -v (or node --version) prints the version number.

Why is Node.js described as non-blocking?

  • It blocks until each task finishes
  • It only runs one line at a time forever
  • It refuses slow tasks
  • Slow work is scheduled so the rest of the code keeps running

Answer: Slow work is scheduled so the rest of the code keeps running. Node schedules slow work and keeps going instead of freezing.

Which global object holds runtime info like the Node version?

  • window
  • process
  • document
  • global.info

Answer: process. The global process object exposes details such as process.version.

What happens if you use window or document in Node?

  • They print a warning then work
  • They are the same as in the browser
  • They throw a ReferenceError — they do not exist in Node
  • They open a browser window

Answer: They throw a ReferenceError — they do not exist in Node. Browser-only globals like window and document do not exist in Node.

What does console.log do in a Node script?

  • Opens a dialog box
  • Saves to a database
  • Sends an HTTP request
  • Writes a line of text to the terminal

Answer: Writes a line of text to the terminal. console.log writes to standard output (the terminal).

In what year did Node.js first let JavaScript run outside the browser?

  • 2009
  • 1999
  • 2015
  • 2020

Answer: 2009. Node.js was released in 2009, bringing JavaScript to servers.

When installing Node from nodejs.org, which build is recommended for learning?

  • The Nightly build
  • The LTS (long-term support) version
  • The Current version
  • The Beta version

Answer: The LTS (long-term support) version. LTS is the stable, well-tested choice for learning and production.