Skip to content

Commit ac4c6e8

Browse files
authored
Update discover-promises-in-nodejs.md
Signed-off-by: Vishal Kumar Gupta <groupsvkg@gmail.com>
1 parent d2b934c commit ac4c6e8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

apps/site/pages/en/learn/asynchronous-work/discover-promises-in-nodejs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ Node.js provides **Promise-based versions** of many of its core APIs, especially
159159
For example, the `fs` (file system) module has a Promise-based API under `fs.promises`:
160160

161161
```js
162-
const fs = require('node:fs');
162+
const fs = require('node:fs').promises;
163163
// Or, you can import the promisified version directly:
164164
// const fs = require('node:fs/promises');
165165

166166
async function readFile() {
167167
try {
168-
const data = await fs.promises.readFile('example.txt', 'utf8');
168+
const data = await fs.readFile('example.txt', 'utf8');
169169
console.log(data);
170170
} catch (err) {
171171
console.error('Error reading file:', err);
@@ -175,7 +175,7 @@ async function readFile() {
175175
readFile();
176176
```
177177

178-
In this example, `fs.promises.readFile()` returns a Promise, which we handle using `async/await` syntax to read the contents of a file asynchronously.
178+
In this example, `fs.readFile()` returns a Promise, which we handle using `async/await` syntax to read the contents of a file asynchronously.
179179

180180
## Advanced Promise Methods
181181

0 commit comments

Comments
 (0)