const express = require('express'); const app = express(); let port = 31009 let counter = 0; app.use("/short", function (req, res) { console.log("short request"); let aa = { 'hits': counter } res.end(JSON.stringify(aa)); }); app.use("/inc", function (req, res) { counter++; res.end(`

Hello

${counter}`); }); function lct(res, currentC) { if (currentC != counter) { console.log("counter changed!"); let aa = { 'hits': counter } res.end(JSON.stringify(aa)); } else { console.log("Counter unchanged"); setTimeout(function () { lct(res, currentC) }, 1000); } } app.use("/long", function (req, res) { console.log("long request"); let currentC = counter; setTimeout(function () { lct(res, currentC) }, 1000); }); app.use("/s", express.static(__dirname)) app.listen(port, function (error) { if (error) throw error console.log("Server created Successfully") });