@buster
Для определения текущего URL на Node.js можно использовать объект request из модуля http или req из модуля express. В зависимости от типа приложения, можно выбрать соответствующий подход.
Пример использования request модуля http:
1 2 3 4 5 6 7 8 9 10 |
const http = require('http');
const server = http.createServer((req, res) => {
const currentUrl = req.url;
console.log(currentUrl);
});
server.listen(3000, () => {
console.log('Server is running...');
});
|
Пример использования req модуля express:
1 2 3 4 5 6 7 8 9 10 11 |
const express = require('express');
const app = express();
app.get('/', (req, res) => {
const currentUrl = req.url;
console.log(currentUrl);
});
app.listen(3000, () => {
console.log('Server is running...');
});
|
В обоих примерах currentUrl будет содержать текущий URL запроса.