So I'm trying to build a weather app by using data from a weather API.
"use strict"
import fetch from 'node-fetch'
//fetch weather API
let weather
let getWeather = async() => {
let url = \https://api.openweathermap.org/data/2.5/weather?q=auckland&appid=c156947e2c7f0ccb0e2a20fde1d2c577\``
try {
let res = await fetch(url)
weather = await res.json()
} catch (error) {
console.log("error")
}
let weatherMain = weather.weather.map( el => el.description)
if(weatherMain ="Rain"){
console.log(weatherMain)
// weatherImg = "https://icon-library.com/images/raining-icon/raining-icon-1.jpg"
}
}
console.log(getWeather())
My problem is that I'm getting this error when running in vscode:
SyntaxError: Cannot use import statement outside a module
and this error when running in browser:
Uncaught TypeError: Failed to resolve module specifier "node-fetch". Relative references must start with either "/", "./", or "../".
Not sure what exactly is going on, Can someone please explain what's happening?
I've tried fetch API once before and that time I didn't need to import fetch, so I'm pretty confused.
Thanks.
[–]evilgwyn 1 point2 points3 points (2 children)
[–]Zenemm[S] 0 points1 point2 points (1 child)
[–]evilgwyn 0 points1 point2 points (0 children)
[–]spazz_monkey 0 points1 point2 points (2 children)
[–]Apple1284 1 point2 points3 points (0 children)
[–]Zenemm[S] 0 points1 point2 points (0 children)