Skip to content

Instantly share code, notes, and snippets.

@andrIvash
Created March 6, 2018 14:26
Show Gist options
  • Select an option

  • Save andrIvash/6da41d513739c2690a80e1b1ce0605eb to your computer and use it in GitHub Desktop.

Select an option

Save andrIvash/6da41d513739c2690a80e1b1ce0605eb to your computer and use it in GitHub Desktop.
hw-node-2_1
const http = require('http');
const time = 20;
const interval = 1;
const port = 8080;
const server = http.createServer(function(req, res){
if (req.method === 'GET' && req.url !== '/favicon.ico') {
console.log('********START timer***********');
const inttime = setInterval(() => {
console.log('echo time = ', Date());
}, Number(interval * 1000));
setTimeout(() => {
console.log('********STOP timer***********')
clearInterval(inttime);
res.end(Date());
}, time * 1000);
}
});
server.listen(port, () => {
console.log('Server running on port: ' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment