const html = `<!DOCTYPE html>
<html>
<head>
<title>sdsd</title>
<meta charset="utf-8">
</head>
<body>
<div>Hello</div>
<script src="exmpl.js">
</script>
</body>
</html>`;
const js = `
async function getData() {
const response = await fetch("data.json");
const json = await response.json();
console.log(json);
}
getData();`;
const json = `
{"Buses":
[ "NumberStop":26,
"NumberBus":9,
"AvgCountPassengers":1,
"Id":1,
"DayOfWeek":1
]
}`
const http = require("http");
http.createServer((req, res) => {
switch (req.url) {
case '/':
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
case '/exmpl.js':
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.end(js);
case '/data.json':
res.writeHead(200, {'Content-Type': 'text/json'});
res.end(json);
default:
res.writeHead(404, {'Content-Type': 'text/plain'});
res.end('ERROR 404');
}
}).listen(3000, () => console.log('server is on'));
сonst http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>sdsd</title>
<meta charset="utf-8">
</head>
<body>
<script>
async function getData() {
const response = await fetch("data.json");
const json = await response.json();
console.log(json);
}
getData();
</script>
</body>
</html>
`);
}).listen(3000);