2

I have Node / Express code:

var express = require('express');
var app = express();
var port = process.env.PORT || 8080;

app.listen(port);
console.log('Server started! At http://localhost:' + port);

app.get('/api/users', function(req, res) {

    var user_id = req.param('id');
    console.log(user_id);

    res.send(user_id );
}); 

When I got to URL in browser (or curl) to http://localhost:8080/api/users?id=4 - output is 4.

How to see any parameter and value that user might enter? e.g. if someone enters: http://localhost:8080/api/users?par1=123&par2=321 it should return par1 = 123 and par2 = 321 etc.

Joe
  • 11,983
  • 31
  • 109
  • 183
  • You could also use the technique shown in [this](https://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-express-js-on-node-js) answer. – TheCodeFox Oct 18 '18 at 13:56

1 Answers1

4

You can use query param of request:

console.log(req.query);

It will contain an object

{
  par1: '123',
  par2: '321'
}
Eugene Tsakh
  • 2,777
  • 2
  • 14
  • 27