async/await implementation of fetchUrl function of fetch package.
npm install async-fetch-url
fetch.fetchUrl(url [, options])
Where
- url is the url to fetch
- options is an optional options object
Options param is same as fetch implementation
Possible options params
{
headers: {
"X-My-Header": "Custom header",
"User-Agent": "MyUseragent/1.0"
},
cookies: ["name=value", "key=value; path=/; secure"],
maxRedirects: 100,//use `disableRedirects: true` to disable redirection, default maxRedirects is 10,
disableGzip: true //default value is false. Gzip and Deflate is on
}
const fetchUrl = require('async-fetch-url').asyncFetchUrl;
( async() => {
var url = "https://www.thehindu.com/";
var response = await fetchUrl(url);
console.log(JSON.stringify(response));
})();
Output format:
{
'error': Object,//error.message to get error info
'meta': Object,
'data': String //html content of the page
}