Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

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

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)})

Be sure to remove your personal API keys when you post code ;)

Nice work with node-fetch!

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

Thanks Nicolas.