Skip to content

Instantly share code, notes, and snippets.

@juandc
Forked from ryanflorence/index.js
Created October 2, 2019 18:42
Show Gist options
  • Save juandc/f229ad9efcca636c330557388f58e1cb to your computer and use it in GitHub Desktop.
Save juandc/f229ad9efcca636c330557388f58e1cb to your computer and use it in GitHub Desktop.
const { createServer } = require('http');
createServer((req, res) => {
res.writeHead(200, {
Connection: 'Transfer-Encoding',
'Content-Type': 'text/html; charset=utf-8',
'Transfer-Encoding': 'chunked'
});
res.write(`
<!doctype html>
<html>
<head><title>chunky!</title></head>
<body>
<h1>Cool Home Page!</h1>
`);
setTimeout(() => {
res.write('<p id="message">Still thinking...</p>');
setTimeout(() => {
res.write(`
<script>
message.innerText = "Embarassing, sorry... here's a button to click:"
</script>
<button id="btn">click me</button>
<script>
btn.addEventListener('click', () => {
const hue = Math.round(Math.random() * 100)
document.body.style.background = "hsl("+hue+", 50%, 90%)"
}, false)
</script>
`);
setTimeout(() => {
res.write(`
<script>
message.innerText = "Whew! Done!"
btn.parentNode.removeChild(btn)
document.body.style.background = ""
</script>
`);
res.end();
}, 5000);
}, 2000);
}, 2000);
}).listen(5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment