JavaScript Node.js Basics Create a Command Line Weather Application Project Overview

Nicholas Smay
Nicholas Smay
Full Stack JavaScript Techdegree Student 10,490 Points

Fetch API?

Is it possible to use the Fetch API with node.js? I used this in previous parts of my course, and much prefer it to the way we are learning to use API's with node.js. Just thought I'd ask!

Cheers!

2 Answers

Nicholas Smay
Nicholas Smay
Full Stack JavaScript Techdegree Student 10,490 Points

Just figured it out. Just used the "node-fetch" module. So much cleaner!

const fetch = require('node-fetch');

fetch('http://api.openweathermap.org/data/2.5/weather?q=London&APPID=15f940b5187ebe422c262ced8c1a6cf0')
  .then(res => {return res.json()})
  .then(json => {console.log(json)})
Ran Wang
Ran Wang
Full Stack JavaScript Techdegree Graduate 25,846 Points

I was wondering about this too, and I though fetch only works on browsers, untill I found this question.

Thanks Nicolas.