req.url node js code example
Example 1: node http request
const https = require('https')
const options = {
hostname: 'whatever.com',
port: 443,
path: '/todos',
method: 'GET'
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
Example 2: get full url nodejs
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
Example 3: node js response header
response.setHeader("Content-Type", "text/html");
Example 4: 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);
});