Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Forked from ryanflorence/index.js
Created October 2, 2019 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save PatrickJS/e4fced2febc7f1a6dccc440f61e3dbfe to your computer and use it in GitHub Desktop.
Save PatrickJS/e4fced2febc7f1a6dccc440f61e3dbfe 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