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

Warning: file_put_contents(): Only 8192 of 16370 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.4158
WE_USE_JS Telegram 4158
👩‍💻 Чтение файла и подсчёт строк

Напишите Node.js скрипт, который читает текстовый файл и выводит количество строк в нём. Если файл не существует, скрипт должен выводить сообщение об ошибке.

Решение задачи🔽

const fs = require('fs');
const filePath = process.argv[2];

if (!filePath) {
console.error('Укажите путь к файлу как аргумент.');
process.exit(1);
}

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Ошибка чтения файла:', err.message);
return;
}

const lines = data.split('\n').length;
console.log(`Количество строк в файле: ${lines}`);
});
Please open Telegram to view this post
VIEW IN TELEGRAM
👍7



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

👩‍💻 Чтение файла и подсчёт строк

Напишите Node.js скрипт, который читает текстовый файл и выводит количество строк в нём. Если файл не существует, скрипт должен выводить сообщение об ошибке.

Решение задачи🔽

const fs = require('fs');
const filePath = process.argv[2];

if (!filePath) {
console.error('Укажите путь к файлу как аргумент.');
process.exit(1);
}

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Ошибка чтения файла:', err.message);
return;
}

const lines = data.split('\n').length;
console.log(`Количество строк в файле: ${lines}`);
});

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


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

View MORE
Open in Telegram


Telegram News

Date: |

Telegram message that reads: "Bear Market Screaming Therapy Group. You are only allowed to send screaming voice notes. Everything else = BAN. Text pics, videos, stickers, gif = BAN. Anything other than screaming = BAN. You think you are smart = BAN. As of Thursday, the SUCK Channel had 34,146 subscribers, with only one message dated August 28, 2020. It was an announcement stating that police had removed all posts on the channel because its content “contravenes the laws of Hong Kong.” Read now "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. Choose quality over quantity. Remember that one high-quality post is better than five short publications of questionable value.
from us


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