Questions tagged [node-fetch]

462 questions
17
votes
1 answer

Node Fetch Post Request using Graphql Query

I'm trying to make a POST request with a GraphQL query, but it's returning the error Must provide query string, even though my request works in PostMan. Here is how I have it running in PostMan: And here is the code I'm running in my application:…
Thomas
  • 2,356
  • 7
  • 23
  • 59
15
votes
2 answers

Writing the stream returned by node-fetch

the README contains the following code as an example of writing a file fetched: fetch('https://assets-cdn.github.com/images/modules/logos_page/Octocat.png') .then(res => { const dest = fs.createWriteStream('./octocat.png'); …
ekkis
  • 9,804
  • 13
  • 55
  • 105
14
votes
2 answers

Using rejectUnauthorized with node-fetch in node.js

I currently use request to make http requests in node.js. I had at some point encountered an issue where I was getting errors that indicated UNABLE_TO_GET_ISSUER_CERT_LOCALLY. To get around that it set rejectUnauthorized. My working code with…
Chris H
  • 501
  • 1
  • 4
  • 15
12
votes
1 answer

Nodejs Parse fetch response containing object [Symbol(map)]

I do not know how to access the parameter x-error-detail-header. I receive this response headers from a request using node-fetch npm package: Headers { [Symbol(map)]: { 'content-type': ['text/xml'], date: ['Fri, 27 Apr 2018 09:46:56…
sendra
  • 658
  • 1
  • 9
  • 21
11
votes
1 answer

node-fetch -- typeof import("[...]/node-fetch/index")' has no call signatures

Copied from here: https://github.com/node-fetch/node-fetch#json ... my code: const fetch = require('node-fetch'); async function doFetch() { const response = await fetch('https://api.github.com/users/github'); const data = await…
DavidT
  • 655
  • 7
  • 19
11
votes
1 answer

How to configure node-fetch to use the company proxy?

I am executing a standalone nodejs script (no web server involved) that needs to fetch result from a third party api. The program uses 'node-fetch' to do the fetch(url) and I run it using node .\test.js from command line. It fails when I am…
Ashok
  • 435
  • 1
  • 4
  • 16
11
votes
1 answer

Mocking node-fetch with jest creating a Response Object for mocking

I am trying to create Response Objects for mocking with jest, I can't seem to get the right syntax. Initialization, jest.mock('node-fetch') const fetch = require('node-fetch') const { Response, Headers } = jest.requireActual('node-fetch') //…
GrandFleet
  • 809
  • 2
  • 10
  • 25
10
votes
0 answers

Connect ETIMEDOUT on Azure App Service when calling HTTP endpoint without specify maxSockets

I have some timeout problems when calling multiple times an HTTP[S] endpoint from node.js inside an Azure App Service. Here my code to demostrate the problem. const fetch = require('node-fetch'); const https = require("https"); const agent = new…
Davide Icardi
  • 11,919
  • 8
  • 56
  • 77
10
votes
4 answers

Catch block not working in node fetch

Trying to learn, Javascript. Pardon if this is really a basic thin i am missing. I am trying to run node-fetch to a wrong url, and i expect that it should be catched and log my appropriate message. However when i run this file through node, it gives…
Raheel
  • 8,716
  • 9
  • 60
  • 102
8
votes
1 answer

response.body.getReader is not a function

I'm making a call to a web api using fetch. I want to read the response as a stream however when I call getReader() on response.body I get the error: "TypeError: response.body.getReader is not a function". const fetch = require("node-fetch"); …
user8565662
  • 127
  • 1
  • 1
  • 6
7
votes
4 answers

Is there a way to pipe ReadableStream into NextApiResponse?

I'd like to display Google Place Photos in my NextJS application. To GET these images from their specified URL an API key is needed, but at the same time, I do not want to expose this API key to the public. My goal is to implement a NextJS API route…
HarrisR
  • 248
  • 3
  • 11
7
votes
2 answers

why is the agent option not available in node native fetch?

I have started using the native fetch function recently (node 17+) I realized today it is lacking a few functionalities from node-fetch, e.g. agent Why is that? Is there are plan to add it? It is a shame because I needed to add node-fetch to my…
John
  • 4,786
  • 8
  • 35
  • 44
7
votes
1 answer

Error "SyntaxError: Cannot use import statement outside a module" when using node-fetch in Jest with Typescript

I am trying to write an integration test in Typescript with Jest which uses node-fetch, like this: import fetch from 'node-fetch'; test('Hello', async () => { await fetch("http://www.google.com"); }); But I am getting the following error: …
devrobf
  • 6,973
  • 2
  • 32
  • 46
7
votes
1 answer

How to use node-fetch with Cloud Functions for Firebase. Can't deploy

I wanna get data with Cloud Functions call from Flutter. Here is my code. const functions = require("firebase-functions"); const admin = require('firebase-admin'); const fetch = require('node-fetch'); admin.initializeApp(); exports.postalCode =…
7
votes
3 answers

Typescript - "Authorization" does not exist on type HeadersInit

I'm using the node-fetch npm module and have a helper function for making authorized requests to a third party service (basically just middleware for adding in the Authorization header). async function makeAuthorizedRequest(url: string, options:…
user3494322
  • 171
  • 3
  • 11
1
2
3
30 31