node js request async await
function doRequest(url) {
return new Promise(function (resolve, reject) {
request(url, function (error, res, body) {
if (!error && res.statusCode == 200) {
resolve(body);
} else {
reject(error);
}
});
});
}
// Usage:
async function main() {
let res = await doRequest(url);
console.log(res);
}
main();
Also in JavaScript:
- How to remove the first and the last character of a string
- play audio javascript
- unix timestamp to date javascript yyyy-mm-dd
- react npm build not working
- how to create a javascript hello world program with node.js
- vue get height of element ref
- how to make a circle in js
- dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.66.dylib Referenced from: /usr/local/bin/node Reason: image not found
- calculate two number and diplay next field without reload the page javascript
- javascript ajax post send an object
- fetch api react
- Geometery parsing GeoJSON
- object methods in javascript
- javascript charcode
- javascript delete first character in string
- react material ui
- jquery vdn
- json file undefined
- get current scroll height javascript
- loop through api response in react
- set display none javascript
- laravel json response
- jquery set hidden field value
- remove character at index