0

I'm writing a Restful api with node js and I'm facing a weird problem: I'm testing the API using a Chrome extension called postman and sending the json object below:

    {
  "items": [
    {
      "appid": 730,
      "classid": "2222",
      "id": 99,
      "instanceid": "instanceID",
      "market_name": "Market name"
    },
    {
      "appid": 730,
      "classid": "2222",
      "id": 99,
      "instanceid": "instanceID",
      "market_name": "Market name"
    }
  ],
  "message": "Mensagem de teste",
  "user": 76561197960275584
}

My problem is with the "user" property. When getting it from the server it returns me 76561197960275580 but the value sent was 76561197960275584. When I send it using string it works but when sending as number - which is like the consumer of the api sends data - it gives me this problem.

Here is some of my API code. It is using express 4.

var express = require('express');
var bodyParser = require('body-parser');
var api = express();

api.use(bodyParser.urlencoded({ extended: false }));
api.use(bodyParser.json());

api.post('/import', function importEndPoint(req, res) {

    console.log('req.body.user=' + req.body.user);
});

Does anyone would have a tip for me to solve it?

Thanks in advance for any help.

André Luiz
  • 6,642
  • 9
  • 55
  • 105
  • Your number simply exceeds JS maximal safe integer (`Number.MAX_SAFE_INTEGER`). You should send it as a string and handle it as string. If you need to handle it as integer, you should have a look at this: http://stackoverflow.com/questions/4288821/how-to-deal-with-big-numbers-in-javascript – crackmigg Jan 31 '16 at 21:00
  • If you cannot control the data that is sent, take a look here: http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint – crackmigg Jan 31 '16 at 21:02
  • Thanks! I will be reading the links. – André Luiz Jan 31 '16 at 21:23

0 Answers0