Не удаётся получить доступ к localhost

Рейтинг: 0Ответов: 1Опубликовано: 14.07.2023

Я запустил сервер, а браузер мне пишет "Не удаётся подключить доступ к сайту". После этого, когда я начал выключать сервер, мне выдало в консоль:

npm ERR! code ELIFECYCLE
npm ERR! errno 3221225786
npm ERR! depositbook@1.0.0 start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the depositbook@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2023-07-14T04_58_37_680Z-debug.log

js:

const https = require('https')
const fs = require('fs')

let server = https.createServer((req, res) => {
    res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'})
    
    const stream = fs.createReadStream('./all/start.html')
    stream.pipe(res)
})

const PORT = 4000
const HOST = 'localhost'

server.listen(PORT, HOST, () => {
    console.log(`Сервак рабочий : https://${HOST}:${PORT}`)
})

Ответы

▲ 0

Начни с самого простого варианта...

const http = require('http');
const https = require('https');
const handler = (req, res) => res.end('<h1>Hello!</h1>');
http.createServer(handler).listen(8080);
https.createServer(handler).listen(8443);

Добавляй изменения шаг за шагом - так поймешь что у тебя ломает весь сервер.

https://digitrain.ru/articles/87657/