-2

Is there a way to use this url http://localhost:3000/assets/img/1.jpg?50 instead of this http://localhost:3000/assets/img/1.jpg/50

app.get('/assets/img/:file/:percentage', (req, res) =>{
        loadImagePercent(req, res, "private/img/"+req.params.file, req.params.percentage);
});
  • Express supports _query parameters_, yes. – jonrsharpe Nov 28 '21 at 09:56
  • Does this answer your question? [How to get GET (query string) variables in Express.js on Node.js?](https://stackoverflow.com/questions/6912584/how-to-get-get-query-string-variables-in-express-js-on-node-js) – peteb Nov 28 '21 at 15:32

1 Answers1

0

You can use query string:

app.get('/assets/img/:file', (req, res) => {
    loadImagePercent(req, res, "private/img/" + req.params.file, req.query.percentage);
});

And your url should be http://localhost:3000/assets/img/1.jpg?percentage=50

Rashomon
  • 5,962
  • 4
  • 29
  • 67