Beginner Fundamentals

Introduction to Node.js

Node.js is a runtime that lets you run JavaScript outside the browser. It is built on top of Google’s V8 engine and is great for building servers, command line tools, and scripts.

What is Node.js

Node.js takes the same language used in the browser and runs it directly on your machine. With it you can read files, talk to databases, and answer network requests, all using JavaScript.

The event loop (overview)

Node.js is single threaded but non blocking. Instead of waiting for a slow task to finish, it registers a callback and keeps working. When the task is done, the event loop runs the callback. This makes Node.js efficient for input and output heavy work.

What it is used for

  • Web servers and REST APIs
  • Command line tools (CLIs)
  • Real time apps (chat, websockets)
  • Build tools and automation scripts

Example

// A tiny Node.js program
console.log("Hello from Node.js!");

// Show the current Node version
console.log("Running on Node", process.version);

Save this as app.js and run it with node app.js. You just executed JavaScript on the server.