Skip to content

Instantly share code, notes, and snippets.

@NeKzor
Created August 31, 2020 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeKzor/cc094f7c32c745f879c5e16073bc9820 to your computer and use it in GitHub Desktop.
Save NeKzor/cc094f7c32c745f879c5e16073bc9820 to your computer and use it in GitHub Desktop.
One-liner fetch API for NodeJs. Fuck axios & co.
const fetch=(u)=>new Promise((x)=>require('https').request(u,{headers:{'User-Agent':'n^'}},(r)=>{let b='';r.on('data',(d)=>b+=d);r.on('end',()=>x(b));}).end());
// Example:
fetch('https://api.github.com/users/NeKzor/followers')
.then(JSON.parse)
.then((followers) => console.log(followers.length));
// > 15
@Lambdac0re
Copy link

lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment