await on the request module gives undefined or never waits
await request(url) returns immediately and the response is undefinedShort answer
await only waits for a promise. The request package works with callbacks and streams, so await request(...) does not wait for the response. The package has been fully deprecated since February 2020. Use the built-in fetch, or wrap the callback API with util.promisify if you must keep request.
Fix it fast
1Find out which cause you have
Check what request returns and whether the package prints a deprecation notice on install.
npm ls request2Match what you see, then jump to its fix
What does the error look like?
await request(url) returns immediately and the response is undefinedrequest has been deprecated
Cause 1 of 2
request is a callback API, so await has no promise to wait for
1Check
The README says request supports streaming and callback interfaces natively, and points to wrapper packages for promises.
grep -rn "require('request')" src/2Fix
Replace it with the global fetch, which Node.js has had built in since version 18 and which no longer needs a flag.
const res = await fetch('https://api.example.com/items');
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();3Verify
Run the file and print the parsed data.
node app.mjsConfirmed by nodejs.org
Cause 2 of 2
You need to keep request for now
1Check
The README says util.promisify (Node.js 8 and later) can turn a callback function into one that returns a promise. It also says request is fully deprecated as of 11 February 2020 and no changes are expected.
npm ls request2Fix
Promisify the call as a stop-gap and plan the move to fetch.
const { promisify } = require('node:util');
const request = require('request');
const get = promisify(request.get);
const res = await get('https://api.example.com/items');
console.log(res.statusCode);3Verify
Run the script and check the status code prints.
node app.jsConfirmed by github.com
How do I stop it coming back?
- Do not add request to new projects; it receives no changes.
- Use fetch in new code and replace old call sites during normal work.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix