NodeJS 如何修复错误“连接ECONNREFUSED”?

x6492ojm  于 2023-04-20  发布在  Node.js
关注(0)|答案(1)|浏览(693)
C:\Users\fc\Desktop\js-basics\Projects>node net.js

给出此错误:

Error: connect ECONNREFUSED 127.0.0.1:8085
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8085
}
z9smfwbn

z9smfwbn1#

有两种方法可以解决这个问题。
1.您可以杀死正在侦听8085 sudo killall node的端口
2.您可以更改端口号。下面是一个工作示例:

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!'); // This will serve your request to '/'.
});

app.listen(8000, function () {
  console.log('Example app listening on port 8000!');
 });

相关问题