Last active
December 20, 2015 18:28
-
-
Save lyle/6175829 to your computer and use it in GitHub Desktop.
A node server that will delay it's response by 1000 milliseconds, or ?delay=milliseconds
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
var url = require('url'); | |
var http = require('http'); | |
http.createServer(function (req, res) { | |
var startTime = Date.now(); | |
var delay = url.parse(req.url, true).query.delay || 1000; | |
setTimeout(function(){ | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('We tried to delay your request by '.concat( | |
delay, | |
' milliseconds.\n', | |
'In reality it took ', | |
(Date.now() - startTime), | |
' milliseconds.\n' | |
)); | |
},delay) | |
}).listen(1337, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:1337/'); | |
console.log('To get a 3 seconds delay: http://127.0.0.1:1337/?delay=3000'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run this via node simply download the index.js file and from a command line: