1

So I got two files my main file

file app.js

var products_id = require('./routes/productId');
app.use('/allProducts/:id',products_id);

and my route file `productId.js``where I am making a request :

router.get('/', function(req, res, next) {}

which I want to access to the parameter that the user pass /allProducts/:id/

cl3m
  • 2,791
  • 19
  • 21

3 Answers3

0

If I understood correctly and you wamt to get the parameters on the server passed through express, see here:

How to get GET (query string) variables in Express.js on Node.js?

Community
  • 1
  • 1
AlexD
  • 4,062
  • 5
  • 38
  • 65
0

Try to check the req object when you enter this route

router.get('/', function(req, res, next){
  console.log(req.query.id);
});

You'll find what you want from here :)

Ben
  • 96
  • 5
0

You might try moving the parameter placeholder out of app.use('/allProducts/:id') (within app.js) and into your router definition (within productId.js).

With that done you'll have: app.use('/allProducts', products_id) in app.js and router.get('/:id', function(req, res, next){...}) in productId.js.

Then you should have access via req.params.id

Will R.
  • 453
  • 3
  • 9