I've been through multiple documentations and sources, but I'm still struggling to fix this error. I recently started learning JavaScript and decided to experiment with fetch() commands, however, I keep encountering an issue (the title).
Below is my code:
index.js
import fetch from 'node-fetch';
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
package.json
{
"name": "Weather-API",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"node-fetch": "^3.0.0"
}
}