get url node js code example
Example 1: express get raw path
const url = require('url');
const express = require('express');
const app = express();
app.use((req, res, next) => {
const path = url.parse(req.url).path;
});
const port = 3000;
app.listen(port, console.log(`Listening on port ${port}.`));
Example 2: node get current url
const fullUrl = `${req.protocol}://${req.get("host")}${req.originalUrl}`;
Example 3: how to get url node
const https = require("https");
const url = https://url.com
app.get("/", function(req, res){
https.get(url, function(res){
console.log(res);
});