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 is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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 lineconsole.log(JSON.parse(data).datetime);
withconsole.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.