In your example, the concept of " Current URL " is meaningless.
Unlike PHP, where each file can handle requests to a separate URL in node.js there is only one centralized application that processes requests to all URLs. There are no "superglobal" variables containing "current URL" in node.js: it can not be : an application can process several requests at the same time.
If we draw analogies with the world of PHP, then this is the same principle used in Symfony: an application receives a request object and must return a response object. However, the URL is known only in the context of the request.
Based on the foregoing, a typical node.js application-HTTP server (without using third-party libraries) can be:
var http = require('http'); var server = http.createServer(function(req, res) { // Вывод URL к которому было произведено обращение console.log(req.url); // Отдача ответа. res.write('output'); res.end(); }); server.listen(8000);
As for the url module, its purpose is to provide you with the means to parse some previously known URL.