res.on('data', is triggered as soon as the first data arrives, not when all data is there. That causes the error, if you replace the line console.log(JSON.parse(data).datetime); with console.log('###'); you'll see that `res.on('data', is triggered multiple times.
As such you're trying to parse an incomplete JSON string, and the error is normal.
Edit: And it's pure luck that it works in node.js.
© Espruino, powered by microcosm.
Report a problem