Home/Tutorials/Node.js/Filesystem Basics

0 of 3 saved

Node.js5 min read

Filesystem Basics

Read this chapter, write the program on this page, then pass a short check to open the next one.

Read and write files.

Filesystem Basics

The fs module reads and writes files. Prefer promise-based fs.promises in new code. In Write tasks we simulate with plain strings.

  • readFile / writeFile are common.
  • Always handle errors.
  • Never trust user paths blindly (path traversal).
const text = "file-ok";
console.log(text);

After you read this chapter, use Write (when available) and Quiz on this page to lock it in.