(I use MacBook Air).
Code is given below :::
const http = require('http');
const fs = require('fs');
const hostname = '127.0.0.1';
const port = 3000;
const home = fs.readFileSync('index.html');
const about = fs.readFileSync('./about.html');
const contact = fs.readFileSync('./contact.html');
const services = fs.readFileSync('./services.html');
const server = http.createServer((req,res)=>{
console.log(req.url);
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.end(home);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
< /code>
Ошибка приведена ниже ::: < /p>
internal/fs/utils.js:307
throw err;
^
Error: ENOENT: no such file or directory, open 'index.html'
at Object.openSync (fs.js:476:3)
at Object.readFileSync (fs.js:377:35)
at Object. (/Users/shouryasharma/Desktop/Web Dev/tut67/index.js:7:17)
at Module._compile (internal/modules/cjs/loader.js
at Object.Module._extensions..js (internal/modules/cjs/loader.js
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: 'index.html'
}
Подробнее здесь: https://stackoverflow.com/questions/669 ... ng-node-js