# Node.js: JavaScript outside the browser

Node.js is a runtime, not another JavaScript language or a browser. It runs JavaScript using V8, exposes APIs such as the filesystem and process, and uses libuv to coordinate asynchronous I/O and the event loop. This makes it useful for command-line tools, development tooling, and servers.

node --version
node -e "console.log('Hello from Node')"
node script.js Alice

A script can read process.argv[2] to get Alice; process.argv[0] is the Node executable and [1] is the script path. A Node process normally exits when no active work remains; a timer, open server, or watcher can keep it alive.

# Why asynchronous I/O?

JavaScript callbacks normally run on one main thread. Node can arrange for I/O to happen through operating-system facilities or libuv's worker pool while JavaScript continues; the callback runs when the result is ready. This does not mean that a long synchronous JavaScript loop automatically moves to another thread:

console.log('start');
setTimeout(() => console.log('timer'), 0);
console.log('end');
// start, end, timer — the timer cannot interrupt synchronous code

A long synchronous loop before the timer's turn simply delays it: the timer fires only after the synchronous work finishes. Busy loops are illustrations of blocking, not a pattern to copy into an application.

Continue with Node vs browser, the event loop, modules and files, npm, and the unchanged pet project.

Node.js introduction (opens new window)