Skip to content
Justice Tech School

fs.promises

fs/promises works with await and never blocks the event loop.

Example
const fs = require("fs/promises"), os = require("os"), path = require("path");
(async () => {
  const f = path.join(os.tmpdir(), "p_n.json");
  await fs.writeFile(f, JSON.stringify({ ok: true }));
  console.log(JSON.parse(await fs.readFile(f, "utf8")));
  await fs.rm(f);
})();

Result

{ ok: true }

Exercise

Async read.

await fs.(f, "utf8")

Quiz Test

Does fs/promises block?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.