NODE.JS 本地主机拒绝连接

时间:2021-04-03 19:35:47

标签: javascript node.js server

我正在尝试自己学习一些后端 Web 开发,但在启动本地服务器时遇到了一些小问题。下面,我将提供我拥有的代码以及我尝试连接时在终端中收到的错误的屏幕截图。

仅供参考:我使用的是 Windows 10,使用 VS 代码,我已经安装了 Node.js。 另外,我正在关注 Web Dev Simplified 的视频教程。视频是“你的第一个 Node.js Web 服务器”

const http = require('http')
const port = 3000

const server = http.createServer(function(req, res)
{
res.write('hello node')
res.end()
})

server.listen(port,function(error)
{
    if(error)
    {   
        console.log('Something went wrong', error)

    }
    else
    {
        console.log('server is listening on port ' + port)

    }
}) 

服务器启动图像。

enter image description here

现在是错误的图像。

enter image description here

这是我尝试连接时 chrome localhost:3000 显示的内容。

enter image description here

我真的很感激有人愿意花时间帮助像我这样的菜鸟!

0 个答案:

没有答案
相关问题