Reputation: 231
I created a server with the express package, and I'm trying to read in a specific way the parameters from the URL. The URL goes like this: http://127.0.0.1:8080/screen=3 (no '?' as the sign for parameters). I need to save the number of the screen in a variable.
I tried this:
var express = require('express');
var app = express();
app.get('/screen:sceenNum', function (req, res) {
var temp = req.sceenNum;
res.send(temp); //for checking on the browser
});
I also tried this, but he must get '?' in the URL:
app.get('/', function(req, res) {
var screenNum = req.param('screen');
res.send(screenNum);
});
Can anyone please have a solution? Thank you
Upvotes: 2
Views: 56
Reputation: 106736
You can access route/url parameters with the req.params
object.
So a route like /screen:screenNum
would accept urls like /screen3
and you would access 3
via req.params.screenNum
.
Similarly, if you want to use the equals, just add that: /screen=:screenNum
and the number is accessed the same.
Upvotes: 1