Node.js Core · 8 min read · Intermediate
File System (node:fs/promises) & Paths
Read, write, and parse JSON files asynchronously using node:fs/promises and cross-platform path.join().
What you'll learn
- Use node:fs/promises with async/await instead of nested callbacks
- Build cross-platform file paths with path.join()
- Specify 'utf8' encoding when reading text files
The node:fs/promises module provides modern Promise-based file operations (readFile, writeFile, mkdir, readdir) that pair cleanly with async / await.
Fill-in-the-Blank Exercise
Async File Read
Read config.json as UTF-8 text using fs/promises.
const fs = require("node:fs/promises");
const text = fs.("config.json", "utf8");Live Code Lab (Node.js 20)
Node.jsfs_demo.js
Expected OutputClick “Run Live” to compile with Node.js 20
Loaded: DevPath | Tracks: 18
Check Your Understanding
Score: 0 / 1
1. What does fs.readFile('notes.txt') return if you omit the 'utf8' encoding argument?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.