AI Workshop: learn to build apps with AI →
Working with Files: How to use the Node.js fs module with async/await

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


Node.js built-in modules famously are not promise-based.

This is for historical reasons, as those modules were created before promises were a thing.

promisify has been available for a long time; Node.js also provides a promise-based fs API.

This API was added in Node.js 10 (2018) and is available only for the fs module.

Here is how to use it:

import * as fs from 'node:fs/promises';

Note: the node:fs prefix identifies Node.js built-in modules.

Now you can use any of the fs methods using promises or await:

const posts = await fs.readdir('content')

Lessons in this unit:

0: Introduction
1: How to check if a file exists in Node.js
2: How to create an empty file in Node.js
3: How to get the names of all the files in a folder in Node
4: How to get the last updated date of a file using Node.js
5: How to remove a file with Node.js
6: How to write a JSON object to file in Node.js
7: How to empty a folder in Node.js
8: Working with file descriptors in Node
9: Node File Paths
10: Node file stats
11: Working with folders in Node
12: ▶︎ How to use the Node.js fs module with async/await
13: How to get the current folder in Node
14: How to get the file extension in Node.js from the MIME type
15: How to get the file extension in Node.js
16: How to list files in a folder in Node
17: How to mass rename files in Node.js
18: Node.js get all files in a folder recursively
19: Incrementing multiple folders numbers at once using Node.js
20: Save some text to a file in Node.js