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.
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:
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 has a vibrant ecosystem with a plethora of libraries, frameworks, and tools. Here are some key components: