2

I'm having a very strange issue whereby getting the time value from my HTTP POST req in express always result in NaN if I'm trying to convert it to ISO String or even Date object.

Here is my URL request: http://localhost:3000/sensor/reading/update?value=33.5&time=1430217238000

update.js

var express = require('express');
var router = express.Router();

var moment = require('moment');

router.post('/', function(req, res, next) {
var time = moment(req.query.time);
}

I am sure that the req.query.time is valid since I can see the exact value in console.log(req.query.time). Even var time = new Date(req.query.time) also result in invalid date.

Totally lost of thoughts here :(

3
  • That's a POST route, you're sure it's GET data you're trying to get ? Commented Apr 28, 2015 at 10:56
  • 1
    Also note that new Date("1430217238000") is in fact not a valid date Commented Apr 28, 2015 at 10:58
  • Indeed this is a HTTP POST to get the time and sensor readings from my sensors and then relay it to another service API like graphing and database. Commented Apr 28, 2015 at 14:02

1 Answer 1

1

You're getting a string, and you probably want an integer

var time = new Date( parseInt( req.query.time, 10) );
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I must have overlooked it. I'm so used to parsing JSON that automatically treat numbers as numbers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.