What Is Node.js?
Running JavaScript outside the browser
- explain what Node.js is (a JavaScript runtime),
- say why JavaScript "left the browser" and what Node is used for,
- run a JavaScript file yourself with the
nodecommand.
1. JavaScript used to live only in the browser
JavaScript was born in 1995 to make web pages come alive: clicking buttons, checking forms, showing pop-ups. To do that, it ran inside the browser (Chrome, Firefox, Safari). The browser gave it special tools like document (the page) and window (the browser tab).
But that also meant JavaScript was trapped. It could not read a file on your computer, or answer requests from other computers, because a web page is not allowed to do those things for safety reasons.
2. Node.js is a JavaScript runtime
A runtime is the program that actually runs your code. Node.js (created in 2009) is a runtime that runs JavaScript. It uses the same fast engine that powers Google Chrome, called V8, and wraps it so JavaScript can work outside a browser.
With Node, JavaScript gains new powers the browser never gave it: it can read and write files, talk to databases, and act as a server that answers requests from the internet.
Important: Node.js is not a new language. The language is still JavaScript. Node is just a new place to run it.