File System (fs)
The fs module lets Node read, write, and manage files. Use the promise version (fs/promises) with async/await so you don't block the server.
import { readFile, writeFile, appendFile, mkdir } from "fs/promises"
async function main() {
await writeFile("notes.txt", "Hello\n")
await appendFile("notes.txt", "World\n")
const text = await readFile("notes.txt", "utf-8")
console.log(text)
await mkdir("logs", { recursive: true })
// Read JSON
const data = JSON.parse(await readFile("data.json", "utf-8"))
}
main()