Придают ошибку при создании сервера с помощью узла JSHtml

Программисты Html
Ответить Пред. темаСлед. тема
Anonymous
 Придают ошибку при создании сервера с помощью узла JS

Сообщение Anonymous »

I created this javascript file , index.html , about.html , contact.html , services.html in a same folder (tut67) but still it is giving error for each html file .
(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:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Html»