Notice: file_put_contents(): Write of 8898 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 17090 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.4474
WE_USE_JS Telegram 4474
👩‍💻 Напишите простой middleware для логирования запросов в Express

Создайте middleware-функцию requestLogger, которая будет логировать метод, URL и время запроса. Такой подход используется в любой серверной логике для отладки, мониторинга и аудита.

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

const express = require('express');
const app = express();

// Middleware для логирования
function requestLogger(req, res, next) {
const start =
Date.now();
res.on('finish', () => {
const duration =
Date.now() - start;
console.log(`${req.method} ${req.originalUrl} → ${res.statusCode} [${duration}ms]`);
});
next();
}

// Подключаем middleware
app.use(requestLogger);

// Пример маршрута
app.get('/', (req, res) => {
res.send('Hello from server!');
});

// Запуск сервера
app.listen(3000, () => {
console.log('Сервер запущен на http://localhost:3000');
});
Please open Telegram to view this post
VIEW IN TELEGRAM
👍3🔥1



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

👩‍💻 Напишите простой middleware для логирования запросов в Express

Создайте middleware-функцию requestLogger, которая будет логировать метод, URL и время запроса. Такой подход используется в любой серверной логике для отладки, мониторинга и аудита.

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

const express = require('express');
const app = express();

// Middleware для логирования
function requestLogger(req, res, next) {
const start =
Date.now();
res.on('finish', () => {
const duration =
Date.now() - start;
console.log(`${req.method} ${req.originalUrl} → ${res.statusCode} [${duration}ms]`);
});
next();
}

// Подключаем middleware
app.use(requestLogger);

// Пример маршрута
app.get('/', (req, res) => {
res.send('Hello from server!');
});

// Запуск сервера
app.listen(3000, () => {
console.log('Сервер запущен на http://localhost:3000');
});

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


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

View MORE
Open in Telegram


Telegram News

Date: |

Invite up to 200 users from your contacts to join your channel The channel also called on people to turn out for illegal assemblies and listed the things that participants should bring along with them, showing prior planning was in the works for riots. The messages also incited people to hurl toxic gas bombs at police and MTR stations, he added. Unlimited number of subscribers per channel “Hey degen, are you stressed? Just let it all out,” he wrote, along with a link to join the group. How to create a business channel on Telegram? (Tutorial)
from us


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