My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

API returns JSON on browser, but weird symbols when I use NodeJS. Why?

Reggie's photo
Reggie
·Mar 16, 2017

Edited my question and added my code. Thanks for pointing it out Marco Alka

When I type this URL in the browser "https://oilspillmonitor.ng/api/spill-data.php?dataset=nosdra&format=json", it returns the data in JSON format. However when I run my code using NodeJS, it just shows me weird symbols.

My code:

'use strict';
let request = require('request');
let url = 'https://oilspillmonitor.ng/api/spill-data.php?dataset=nosdra&format=json';
request.get({ url: url },  (err, res, data)  =>  { 
 if (err) {
  console.log('Error: ', err); 
 } else {
  console.log(data);
 }
});