Notice: file_put_contents(): Write of 5217 bytes failed with errno=28 No space left on device in /var/www/tgoop/post.php on line 50

Warning: file_put_contents(): Only 12288 of 17505 bytes written, possibly out of free disk space in /var/www/tgoop/post.php on line 50
Node.JS [ru] | Серверный JavaScript@we_use_js P.4515
WE_USE_JS Telegram 4515
⚙️ Что такое fs.promises в Node.js и зачем он нужен?

Модуль fs в Node.js позволяет работать с файловой системой. Начиная с Node 10+, появился fs.promises, который возвращает Promise вместо использования колбэков.

Это делает код чище и позволяет писать асинхронные операции через async/await

➡️ Пример:

const fs = require('fs/promises');

async function readFile() {
try {
const data = await fs.readFile('example.txt', 'utf8');
console.log(data);
} catch (err) {
console.error('Ошибка чтения файла:', err);
}
}

readFile();


🗣️ В этом примере файл example.txt читается асинхронно. Ошибки обрабатываются через try/catch, код становится линейным и легко читаемым.


Это современный способ работы с файлами в Node.js без "адских вложенных колбэков".

🖥 Подробнее тут
Please open Telegram to view this post
VIEW IN TELEGRAM
👍5🔥2🤨1



tgoop.com/we_use_js/4515
Create:
Last Update:

⚙️ Что такое fs.promises в Node.js и зачем он нужен?

Модуль fs в Node.js позволяет работать с файловой системой. Начиная с Node 10+, появился fs.promises, который возвращает Promise вместо использования колбэков.

Это делает код чище и позволяет писать асинхронные операции через async/await

➡️ Пример:

const fs = require('fs/promises');

async function readFile() {
try {
const data = await fs.readFile('example.txt', 'utf8');
console.log(data);
} catch (err) {
console.error('Ошибка чтения файла:', err);
}
}

readFile();


🗣️ В этом примере файл example.txt читается асинхронно. Ошибки обрабатываются через try/catch, код становится линейным и легко читаемым.


Это современный способ работы с файлами в Node.js без "адских вложенных колбэков".

🖥 Подробнее тут

BY Node.JS [ru] | Серверный JavaScript


Share with your friend now:
tgoop.com/we_use_js/4515

View MORE
Open in Telegram


Telegram News

Date: |

"Doxxing content is forbidden on Telegram and our moderators routinely remove such content from around the world," said a spokesman for the messaging app, Remi Vaughn. According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. Clear Judge Hui described Ng as inciting others to “commit a massacre” with three posts teaching people to make “toxic chlorine gas bombs,” target police stations, police quarters and the city’s metro stations. This offence was “rather serious,” the court said. Earlier, crypto enthusiasts had created a self-described “meme app” dubbed “gm” app wherein users would greet each other with “gm” or “good morning” messages. However, in September 2021, the gm app was down after a hacker reportedly gained access to the user data.
from us


Telegram Node.JS [ru] | Серверный JavaScript
FROM American