Node and Files
JavaScript on your computer.
Node lets JavaScript run outside the browser, on your computer or on a server. There's no page and no DOM. Instead, Node gives you modules for files, networks, and the operating system. It's how JavaScript is used for back ends, tools, and scripts.

- JavaScript outside the browser
- No page, no DOM
- Files, networks, the system
Reading and writing files
We import the promise version of the f s module, short for file system. Write file creates a file with some text. Read file reads it back, as a string when we give it an encoding. Append file adds to the end. And readdir lists the files in a folder. Run it.
import { writeFile, readFile, appendFile, readdir } from "node:fs/promises";
await writeFile("notes.txt", "Buy milk\n");
await appendFile("notes.txt", "Call Sam\n");
const text = await readFile("notes.txt", "utf8");
console.log(text.trim().split("\n"));
const files = await readdir(".");
console.log(files.includes("notes.txt"));[ 'Buy milk', 'Call Sam' ] true
process and path
Process tells you about the running program. Process dot argv holds command line arguments, and process dot env holds environment variables. The path module joins folder and file names safely, on any operating system. Run it.
import path from "node:path";
console.log("Node version:", process.version.split(".")[0]);
console.log("Arguments:", process.argv.length);
console.log("Home set:", process.env.HOME !== undefined);
const file = path.join("reports", "2026", "summary.txt");
console.log(file, path.extname(file), path.basename(file));Node version: v22 Arguments: 2 Home set: true reports/2026/summary.txt .txt summary.txt
Summary
Node runs JavaScript outside the browser. The f s module reads and writes files, and process and path tell you about the system. Next, npm and package dot JSON.
Key takeaways- node app.js
- fs/promises
- process, path