Search code examples
javascriptjsonnode.jspostpug

node.js - sending an integer as the input parameter in POST request


I am trying to input an integer from the user (.jade page) and pass that value as body parameter. When I try to use the below code, the value is getting converted to string. Can you please help me in this.

app.js

 var empid = req.body.empid;  // getting value from the jade page
 console.log(empid); // output here is 1111
 var requestdata = {1:empid};
 console.log(requestdata); // output here is '1111'
  var options = {
    url: my URL goes here,
    method: 'POST',
    headers: {
          'Content-Type': 'application/json'
      },
    auth: {
    user : username,
    pass : '****'
          },
    body: JSON.stringify(requestdata)
}

I want the value to be 1111 when I try to pass that into the POST request.


Solution

  • You can pass as string and convert to int on server side like this:

    parseInt(arg);