forked from fbw-d09/be-intro-server-imadteryaki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
36 lines (29 loc) · 837 Bytes
/
Server.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
// Import required modules
const http = require('http');
// Load environment variables from .env file
require("dotenv").config();
// Initialize a counter
let counter = 0;
// Create a server instance
const port = process.env.PORT;
const server = http.createServer((req, res) => {
switch (req.url) {
case "/":
res.write("Hello World");
res.end();
break;
case "/now":
res.write(`${ new Date().toLocaleDateString("de-DE") }, ${ new Date().toLocaleTimeString("de-DE") }`);
res.end();
break;
case "/count":
res.write(`${ counter }`);
counter++;
res.end();
break;
};
});
// Start the server
server.listen(port, () => {
console.log(`Der Server läuft auf Port ${ port }.`);
});