Questions tagged [node-fetch]

462 questions
208
votes
3 answers

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported

I'm trying to make a Discord bot that just says if someone is online on the game. However I keep getting this message: [ERR_REQUIRE_ESM]: require() of ES Module from not supported. Instead change the require of index.js in... to a dynamic import()…
N-Man
  • 2,851
  • 2
  • 4
  • 7
121
votes
14 answers

Error: require() of ES modules is not supported when importing node-fetch

I'm creating a program to analyze security camera streams and got stuck on the very first line. At the moment my .js file has nothing but the import of node-fetch and it gives me an error message. What am I doing wrong? Running Ubuntu 20.04.2 LTS in…
Roope Kuisma
  • 1,320
  • 2
  • 3
  • 7
77
votes
7 answers

require('node-fetch') gives ERR_REQUIRE_ESM

I just use const fetch = require('node-fetch') And I get Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\rollbot\index.js not supported. Instead change…
Alex Stroescu
  • 972
  • 1
  • 7
  • 15
75
votes
3 answers

How to send cookies with node-fetch?

I've got nodejs application which handles user's requests and receives cookies which i want to proxy to internal API service. How to approach this by using node-fetch? Don't offer superagent please.
Skay
  • 9,343
  • 6
  • 27
  • 28
60
votes
2 answers

Node-fetch: Disable SSL verification

I have the following code, which is run from a express server: import fetch from 'node-fetch'; let formBody = []; const dataLogin = { 'username': 'myUser', 'password': 'myPassword' }; for (let p in dataLogin) { let encodedKey =…
Allan Martins
  • 732
  • 1
  • 5
  • 9
54
votes
2 answers

How to send a file in request node-fetch or Node?

How do I attach a file in Node or Node Fetch POST request? I am trying to invoke an API which will import a CSV or XLS file. Is this possible using Node or Node Fetch?
Rocky
  • 857
  • 2
  • 8
  • 15
37
votes
1 answer

How to ignore SSL certificate validation in node requests?

I need to disable peer SSL validation for some of my https requests using node.js Right now I use node-fetch package which doesn't have that option, as far as I know. That should be something like CURL's CURLOPT_SSL_VERIFYPEER => false,…
Dmitry Samoylov
  • 1,228
  • 3
  • 17
  • 27
37
votes
5 answers

POSTing to external API throws CORS but it works from Postman

I am using the imgur api to upload images via a node js app. I am converting images to base64 strings and sending them via Postman works great. I use node-fetch to make api calls. const fetch = require('node-fetch') ... async…
Cristian G
  • 460
  • 1
  • 4
  • 22
35
votes
2 answers

node-fetch 3.0.0 and jest gives SyntaxError: Cannot use import statement outside a module

I'm trying to upgrade my api to use node-fetch 3.0.0. Part of the breaking changes in their documentation is that node-fetch is now a pure ESM module. https://github.com/node-fetch/node-fetch/blob/main/docs/CHANGELOG.md My unit tests have started…
avenmia
  • 2,015
  • 4
  • 25
  • 49
33
votes
2 answers

Node-fetch problems with POST requests

In postman, I can successfully make this request: And get this response: Now I want to do the same request in my server.js file in node.js: const fetch = require('node-fetch') const SEN_URL = "http://www.sentiment140.com/api/bulkClassifyJson" //…
Sahand
  • 7,980
  • 23
  • 69
  • 137
30
votes
3 answers

How to make request body type compatible with RequestInit or BodyInit when using node-fetch?

I started to use Typescript for my nodejs project. For accessing some external API, I use node-fetch to make requests. While setting up a PUT request, an error pops up, saying that the given body is not assignable to type RequestInit: The…
Leon Joosse
  • 959
  • 1
  • 7
  • 17
22
votes
1 answer

Is there a way to log the node-fetch request?

So I'm trying to use some APIs in node.js using node-fetch and I would like to log the final request that is being sent to the server, but I can't find any way how to do it. Can you help me please? Here is the code: const fs = require('fs'); const…
Andrei Manolache
  • 766
  • 1
  • 8
  • 17
21
votes
2 answers

Node Fetch Request Fails on Server: Unable to Get Local Issuer Certificate

~ I'm using Node 10.9.0 and npm 6.2.0 ~ I have the following app running that allows me to make a request to the same site over http and over https. var fetch = require('node-fetch') const express = require('express') const app = express() //--…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
21
votes
4 answers

How to get data and response status from API using node-fetch?

As per the node-fetch documentation node-fetch we can get the response status like this fetch('https://github.com/') .then(res => { console.log(res.status); }); and for getting the data fetch('https://api.github.com/users/github') …
Dony Joseph
  • 499
  • 2
  • 5
  • 10
17
votes
4 answers

Javascript node-fetch synchronous fetch

I'm trying to use node-fetch with nodejs to make api calls to my personal api. I would like to be able to update certain values synchronously within this periodically as things update/change with my database behind the scenes. I know that async and…
Wallace Alley
  • 173
  • 1
  • 1
  • 5
1
2 3
30 31