Created
April 5, 2019 18:40
-
-
Save tizzo/608c4cbe3467b4808173e0dc3db440e7 to your computer and use it in GitHub Desktop.
This file contains 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 net = require('net'); | |
const https = require('https'); | |
const filePath = '/tmp/kanye'; | |
const server = net.createServer(async (stream) => { | |
stream.end(await getKanyeQuote() + '\n'); | |
}); | |
server.listen(filePath, () => { | |
console.log(`Now listening on ${filePath}`); | |
}); | |
async function getKanyeQuote() { | |
return new Promise((accept, reject) => { | |
https.get('https://api.kanye.rest/', (resp) => { | |
let data = ''; | |
resp.on('data', (chunk) => { | |
data += chunk; | |
}); | |
resp.on('end', () => { | |
console.log(JSON.parse(data).quote); | |
}); | |
}).on("error", (err) => { | |
console.log("Error: " + err.message); | |
}); | |
}); | |
} | |
This file contains 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
node kanye-socket.js & | |
cat /tmp/kanye |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment