Questions tagged [node.js-got]

"Human-friendly and powerful HTTP request library for Node.js"

51 questions
33
votes
1 answer

JEST Received function did not throw, but HTTPError is thrown

I am testing an endpoint with JEST and Got. I expect 403 Forbidden error. The following code prints the error from catch block AND fails that the identical call does not throw an error. Why? try { response = await…
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
10
votes
1 answer

got npm module : How to retry for POST requests?

The below example is for GET requests, but does not work for POST requests. How can I make it work for POST? https://www.npmjs.com/package/got#retry const got = require('got') const retry = { retry: { retries: 3 …
Darshan Naik
  • 271
  • 1
  • 4
  • 15
8
votes
3 answers

Must use import to load ES module: ...\node_modules\got\dist\source\index.js

There's dozens of other questions with basically the same title, but none of the answers seem to be relevant and just add to the confusion. This is my tsconfig.json: { "compilerOptions": { "target": "es6", "module": "commonjs", "lib":…
Clonkex
  • 3,373
  • 7
  • 38
  • 55
6
votes
2 answers

Got npm module: How to add bearer token to POST request

I recently found out that request is no longer maintained, so the best alternative I found is got. I am trying to make an external API call to a REST Server but I am unsure as to how I can add a Bearer token in the authorization header of the POST…
aieyan
  • 123
  • 4
  • 7
5
votes
3 answers

How to import got in typescript?

i'm trying to import got from 'got' in my typescript program to convert an url to a streamable file, but I tryed to import it in different ways and i obtaining always errors like : can only be default-imported using the 'esModuleInterop' flag my…
user16560224
4
votes
2 answers

How to import a Javascript file that is ESM from a CommonJS module? Got. Error: Not supported

My project is written entirely in CommonJS module and I can't change it. I am trying to use a library which is an ESM. The library is Got library (https://github.com/sindresorhus/got). This is my code const request = require('request'); const…
Vipresh
  • 1,250
  • 15
  • 31
4
votes
1 answer

Building Got with Typescript - Nodejs

I'm trying to use Got with Typescript and ESM, and since Got is written in typescript itself I understand that it is supposed to be easy to integrate. I even followed this guide written by the author of Got which is very detailed and…
3
votes
1 answer

Node.js process doesn't exit when run under pm2

I have a node.js script that runs and exits fine in console, but it doesn't exit unless I call process.exit() in pm2. PM2 config is: { name: "worker", script: "./worker.js", restart_delay: 60000, …
3
votes
5 answers

How to calculate the time spent when using got?

Example code: const got = require('got'); async function timeSpent (){ const time = new Date().getTime() await got('***') return new Date().getTime() - time } I wonder if there is a better way?
ebyte
  • 1,469
  • 2
  • 17
  • 32
2
votes
1 answer

Piping got.stream to a file

I am refactoring some code that was using http module in Node to use got instead. I tried the following: function get(url, filePath) { return new Promise((resolve, reject) => { got.stream(url).on ("response", response => { …
Old Geezer
  • 14,854
  • 31
  • 111
  • 198
2
votes
1 answer

how to troubleshoot using the node.js GOT http request library?

I have some code using GOT querying a graphQL endpoint: // set up params for call to weather cache const queryQL = ` query weather { weather(where: {idLatLong: {_eq: "${latLong}"}}) { id idLatLong …
user1048175
  • 1,100
  • 3
  • 12
  • 29
1
vote
0 answers

GOT package: RequestError: The body option must be a stream.Readable, string or Buffer

I am getting this error while trying to hit the POST and PUT APIs using GOT package in Node.Js (for external API calling). I am using Got@11.8.6 with Node.js version 16.18.1 in Windows 10 OS. Code Snippet const gotObject = { method: 'POST', json:…
Ketav
  • 760
  • 1
  • 8
  • 27
1
vote
0 answers

how to create a readable stream from a remote URL and pass it into another API without saving it into the local file system in nodejs using got?

I want to access an image from a remote URL and pass it into another API request as request body. I am using got stream API library to stream the data from the external url. const url =…
Sufail Kalathil
  • 558
  • 6
  • 21
1
vote
1 answer

using https.get instead of got causes a 308

this is a difficult question to ask because I am mystified, but let's see… I am comparing Got with https.get, and have the following, bare simple code that works. Both Got and https.get return exactly the same result. But when I use exactly the same…
punkish
  • 13,598
  • 26
  • 66
  • 101
1
vote
0 answers

NPM module I've installed is causing Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

I've installed the got NPM module into my project but now it's causing problems. It's saying to remove type:module but I can't do that since it's an NPM module and not mine. How do I get around this? It's a fresh project that's been generated with…
user9754798
  • 363
  • 3
  • 15
1
2 3 4