Created
June 8, 2017 07:16
-
-
Save palmerabollo/9d7f83088e9c8b24f43fe20dc2ddddf2 to your computer and use it in GitHub Desktop.
Node HTTP server with delayed response
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 http = require('http'); | |
const url = require('url') ; | |
let server = http.createServer((req, res) => { | |
let query = url.parse(req.url, true).query; | |
res.writeHead(200, {'Content-Type': 'application/json'}); | |
setTimeout(() => { | |
res.write(JSON.stringify({success: true})); | |
res.end(); | |
}, query.delay); | |
}); | |
server.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment