JavaScript How to capture indefinite number of parameters in Express Route?

Say I have an express route that takes numbers, adds them all up and returns the total.

Normally I would do something like this

app.get('/add/:num1/:num2/:num3', (req, res) => {
   // access and parseInt these values from req.params
   // do operations
   // return total
})

In this case, however, the number of parameters the route can handle is limited to 3 (or however many url parameters I hard code). What if I wanted to handle an indefinite or unknown number of parameters? In this case, numbers?

Ultimately I want the route to be able to handle 2, 3, 5, 10, or 20 numbers if that's what the user sends.

How can I achieve that?

Answer:1

const fs = require('fs'); // const util = require('util'); let text = ``; const files = [`head.txt`,`body.txt`,`leg.txt`,`feet.txt`]; let head,body,leg,feet = ``; //const readFile = util.promisify(...

const fs = require('fs'); // const util = require('util'); let text = ``; const files = [`head.txt`,`body.txt`,`leg.txt`,`feet.txt`]; let head,body,leg,feet = ``; //const readFile = util.promisify(...

  1. async/await function in javascript
  2. async await function
  3. async await function javascript
  4. async await function return value
  5. async await function javascript example
  6. async await function nodejs
  7. async await function js
  8. async await function example
  9. async await function react
  10. async await function typescript
  11. async await function with callback
  12. async await function c#
  13. async await function return promise
  14. async await function return
  15. async await function react native
  16. async await function expression
  17. async await function es6
  18. async await function angular
  19. async await function call
  20. async await function angular 6

Is it possible to put JSX inside a template string that is being used as a React render prop? This is what I'm trying to do, but it leads to the link rendering as [object Object] const Container = ({...

Is it possible to put JSX inside a template string that is being used as a React render prop? This is what I'm trying to do, but it leads to the link rendering as [object Object] const Container = ({...

  1. template string within template string

I'm using the Object.assign() to copy values to an object: const { one, two, three } = attributes; return Object.assign( props, { "data-one": one, "data-two": two, "data-three": three } ); ...

I'm using the Object.assign() to copy values to an object: const { one, two, three } = attributes; return Object.assign( props, { "data-one": one, "data-two": two, "data-three": three } ); ...

I have a problem I am sitting on for the past few days. I want to write an optimal (in JS) program for verifying if a number is a Palindrome. My current approach: function isPalidrom2(pali){ ...

I have a problem I am sitting on for the past few days. I want to write an optimal (in JS) program for verifying if a number is a Palindrome. My current approach: function isPalidrom2(pali){ ...