当我尝试使用节点创建服务器时出现错误。nodemon 崩溃了

问题描述 投票:0回答:1

this is my code along with the error

这应该在指定端口上创建一个服务器。错误是 Nodemon 应用程序在启动前等待文件更改时崩溃了。我尝试更改端口但没有帮助,并且后台没有运行服务器。

javascript node.js server backend nodemon
1个回答
0
投票

您不能将参数作为字符串传递给

server.listen

const http = require('http');
const PORT=2000;
const HOST="localhost";

const server = http.createServer((req, res, next) => {
    if(req.url == "/about"){
        return res.end("<h1> About page</h1>")
    }
})

server.listen(PORT, HOST,()=>{
    console.log(`server is running on http://${HOST}:${PORT}`)
})
© www.soinside.com 2019 - 2024. All rights reserved.