Written by Sümeyye Sever (notes I took while creating web development projects)


Node.js is a runtime environment that allows you to execute JavaScript code outside of a browser. It is built on the V8 JavaScript engine (the same engine used by Google Chrome) and is widely used for server-side development.

What does “outside of a browser” mean?

Traditionally, JavaScript was only executed within the browser to add interactivity to web pages (like handling clicks or updating content dynamically). However, with Node.js, you can run JavaScript outside of the browser, meaning:

  1. Not tied to a web page: JavaScript can be executed on a computer or server directly, without requiring a browser.
  2. Server-side programming: You can write backend code (e.g., creating APIs, handling file systems) using JavaScript, which was previously not possible without a browser.
  3. Command-line tools: Use JavaScript to create tools and scripts that run in the terminal.
  4. Full-stack development: Developers can use JavaScript both for frontend (browser) and backend (server).

Example: Inside vs. Outside the Browser

Inside the Browser:

document.querySelector('button').addEventListener('click', () => {
  alert('Button clicked!');
});

Here, the code runs within the browser and manipulates the web page's Document Object Model (DOM).

Outside the Browser (Node.js):

const fs = require('fs');

// Read a file
fs.readFile('example.txt', 'utf-8', (err, data) => {
  if (err) console.error(err);
  else console.log(data);
});

Here, the code runs on a computer/server using Node.js, without involving any web page or browser.

Node.js Ecosystem

Node.js has a vibrant ecosystem with a plethora of libraries, frameworks, and tools. Here are some key components:

  1. npm (Node Package Manager): npm is the default package manager for Node.js. It allows developers to install, manage, and share reusable code packages (called modules). You can find thousands of open-source packages on the npm registry.