-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
39 lines (32 loc) · 856 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var http = require('http');
var sleep = require('sleep');
const fib = () => {
console.log('Calculating the Fibonacci sequence...');
let [f0, f1] = [0, 1];
while (true) {
const sum = f0 + f1;
f0 = f1;
f1 = sum;
console.log(f0);
sleep.sleep(1);
}
};
switch (process.argv[process.argv.length - 1]) {
case 'web':
if (!process.env.PORT) {
console.error("PORT environment variable not set");
process.exit(1);
}
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(`Hi, I love ${req.url.slice(1)}!\n`);
}).listen(process.env.PORT, "0.0.0.0");
console.log(`Server running at http://0.0.0.0:${process.env.PORT}/`);
break;
case 'worker':
fib();
break;
default:
console.error('please specify web or worker');
process.exit(1);
};