I am trying to fetch API data using Node JS. I am using this node package to do so.
https://www.npmjs.com/package/cryptocompare
The documentation of that package is easy enough.
global.fetch = require('node-fetch')
const cc = require('cryptocompare')
cc.price('BTC', ['USD', 'EUR'])
.then(prices => {
console.log(prices)
})
.catch(console.error)
I've tested it with npm.runkit.com and it works.
However, when I install the package into my app, I don't see any output in the console.
I am using JetBrains WebStorm and these are the steps I've taken.
- Create New Express App
- npm install -g express-generator
- npm install --save node-fetch
- npm install --save cryptocompare
- npm install
Then within /routes/index.js I added the following
var express = require('express');
var router = express.Router();
global.fetch = require('node-fetch');
const cc = require('cryptocompare');
/* GET home page. */
cc.price('BTC', ['USD'])
.then(prices => {
console.log(prices)
}).catch(console.error);
router.get('/', function(req, res, next) {
res.render('index', {
title: 'Example'
});
});
module.exports = router;
But that displays nothing in the console log. I tried moving the global.fetch to app.js in the root directory but that didn't do anything either.
What am I doing wrong here?
USD?