首页 > 解决方案 > 创建本地主机服务器时如何克服此错误?

问题描述

这是我在此代码中输入的代码,并且在浏览器中显示错误

const http = require('http');
const server = http.createServer((req , res) =>{
    res.end('Hello fromm the server!');
});

server.listen(8000, '127.0.0.1', () => {
    console.log('Listening to request on port 8000');
})

在此处输入图像描述

标签: javascriptnode.jsserverlocalhostmean-stack

解决方案


我无法重现此问题。您是否在终端中执行了节点脚本?

在此示例中,我将文件命名为“index.js”

node index.js

执行节点脚本后,您的终端应显示“正在侦听端口 8000 上的请求”。

在此处输入图像描述


推荐阅读