Ошибка throw err; при создании сервера. Что делать?
Создаю сервер на JS. Закончил код и перехожу к запуску самого сервера. Используя VScode, захожу в терминал, ввожу "node server" и выдаёт ошибку:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:\Users\Никита\server'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Соответственно и через localhost результатов нет.
Путь файла: PS C:\Users\Никита>
Вот сам код: //server.js
const http = require('http');
const html = `
<!DOCTYPE>
<html>
<head>
<meta charset = "UTF-8">
<title>Coding in Node.js</title>
<link rel = "stylesheet" href = "app.css">
</head>
<body>
<h1>JS</h1>
<button>button</button>
<script src = "app.js"></script>
</body>
</html>
`;
const css = `
body {
margin: 0;
padding: 0;
text-align: left;
}
h1 {
background-color: #43853d;
padding: .7em;
font-family: 'Consolas';
}
`;
const js = `
const button = document.querySelector('button');
button.addEventListener('click', event => alert('Node.js'));
`;
http.createServer((req, res) => {
switch (req, url) {
case '/':
res.writeHead(200, { 'Content-Type': 'text/html ' });
res.end(html);
case '/app.css':
res.writeHead(200, { 'Content-Type': 'text/css ' });
res.end(css);
case 'app.js':
res.writeHead(200, { 'Content-Type': 'text/javascript ' });
res.end(js);
defult: res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('404 Not Found');
}
}).listen(3000, () => console.log('Сервер работает.'));