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

Warning: file_put_contents(): Only 16384 of 17190 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.4309
WE_USE_JS Telegram 4309
👩‍💻 Задачка по NodeJS

Создайте приложение на Node.js, которое принимает URL, отправляет запрос к этому URL, и сохраняет заголовки ответа в файл headers.json. Программа должна также уметь выводить заголовки в консоль.

➡️ Пример:

node app.js fetch https://example.com — выводит заголовки в консоль и сохраняет их в файл headers.json.

Решение задачи ⬇️

const https = require('https');
const fs = require('fs');

function fetchHeaders(url) {
https.get(url, (res) => {
const headers = JSON.stringify(res.headers, null, 2);
console.log(headers);
fs.writeFileSync('headers.json', headers);
}).on('error', (err) => console.error('Ошибка:', err));
}

// Использование
const url = process.argv[2];
if (url) fetchHeaders(url);
else console.log('Укажите URL.');
Please open Telegram to view this post
VIEW IN TELEGRAM
👍4🥱41💩1



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

👩‍💻 Задачка по NodeJS

Создайте приложение на Node.js, которое принимает URL, отправляет запрос к этому URL, и сохраняет заголовки ответа в файл headers.json. Программа должна также уметь выводить заголовки в консоль.

➡️ Пример:

node app.js fetch https://example.com — выводит заголовки в консоль и сохраняет их в файл headers.json.

Решение задачи ⬇️

const https = require('https');
const fs = require('fs');

function fetchHeaders(url) {
https.get(url, (res) => {
const headers = JSON.stringify(res.headers, null, 2);
console.log(headers);
fs.writeFileSync('headers.json', headers);
}).on('error', (err) => console.error('Ошибка:', err));
}

// Использование
const url = process.argv[2];
if (url) fetchHeaders(url);
else console.log('Укажите URL.');

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


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

View MORE
Open in Telegram


Telegram News

Date: |

In the “Bear Market Screaming Therapy Group” on Telegram, members are only allowed to post voice notes of themselves screaming. Anything else will result in an instant ban from the group, which currently has about 75 members. Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. The Channel name and bio must be no more than 255 characters long When choosing the right name for your Telegram channel, use the language of your target audience. The name must sum up the essence of your channel in 1-3 words. If you’re planning to expand your Telegram audience, it makes sense to incorporate keywords into your name. Unlimited number of subscribers per channel
from us


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