nodejs express get url code example
Example 1: express get url parameters
app.get('/path/:name', function(req, res) {
res.send("tagId is set to " + req.params.name);
});
Example 2: 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 3: get full url nodejs
var fullUrl = req.protocol + '://' + req.get('host') + req.originalUrl;
Example 4: node js express url parameters
app.get('/api/:version', function(req, res) {
res.send(req.params.version);
});