Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save palmerabollo/9d7f83088e9c8b24f43fe20dc2ddddf2 to your computer and use it in GitHub Desktop.
Save palmerabollo/9d7f83088e9c8b24f43fe20dc2ddddf2 to your computer and use it in GitHub Desktop.
Node HTTP server with delayed response
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