javascript - Node.js localhost:3000 拒绝连接
问题描述
我是 Node.js 的初学者,无法连接到 localhost:3000
我在VS代码中使用以下代码,在终端中点击“node app.js”,此时终端中没有错误出现。但是,当我尝试访问 localhost:3000 时,它一直拒绝:“ERR_CONNECTION_REFUSED” 我在互联网上搜索解决方案并尝试通过在安全设置上创建入站规则来打开端口,打开 IIS,改用 127.0.0.1,然后仍然被拒绝。有谁知道如何解决这个问题?
我正在使用 Windows 10
const http = require('http');
var server = http.createServer(
(request, response)=>{
response.end('hello');
}
);
server.listen(3000);
解决方案
这是修复它的方法。您可能尝试在使用的端口上启动您的服务器。
// enter this command in your terminal
lsof -i:3000
// this will output the related PID (process ID). Here: 1382.
node 1382 name 21u IPv6 blabla 0t0 TCP *:3000 (LISTEN)
// kill the PID in use
kill -9 1382
//relaunch your server
node app.js
推荐阅读
- c# - 如何在c#中搜索日期并检查它是否存在于日期时间数组中
- priority-web-sdk - priority-web-sdk:选择字段的 fieldUpdate 失败
- python - 不同应用程序的 Django 迁移
- json - 从雪花中的 JSON 数组中求和值
- c# - 计划不应接受计划时间前 1 小时
- javascript - 如何在 Springboot 应用程序中设置标头 X-Content-Type-Options “nosniff”?
- oracle - Oracle - .CSV 文件一次到多个表
- javascript - 如何使用 rxjs / angular observable 发布一个值
- opencv - 合并解压BGR通道后编译成功,但运行时出现错误:ILLEGAL OPERATION
- wordpress - 自定义帖子类别正在相互合并