Created
August 31, 2020 17:16
-
-
Save NeKzor/cc094f7c32c745f879c5e16073bc9820 to your computer and use it in GitHub Desktop.
One-liner fetch API for NodeJs. Fuck axios & co.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lol