Node.js · Junior · Question 35 of 75
How do you get a promise-based version of the fs API?
- 1
fs.readFilealready returns a promise if you omit the callback - ✓Correct answer:
import { readFile } from "node:fs/promises" - 3
import { readFileAsync } from "node:fs"
Explanation
fs/promises has the same functions that return promises, so you can write const text = await readFile(path, "utf8").