最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Node.jsExpress 错误:连接 ECONNREFUSED 127.0.0.1:5000

网站源码admin40浏览0评论

Node.js/Express 错误:连接 ECONNREFUSED 127.0.0.1:5000

Node.js/Express 错误:连接 ECONNREFUSED 127.0.0.1:5000

操作系统 - Windows 10 专业版
Node.js - 版本 5.9.1

嗨,

所以我在 nodeJS/Express 下运行我的应用程序时收到上述错误消息。

我的server/app.js文件如下:

'use strict';


// Set default node environment to development

var connectionString = config.mongo.connectionstring;

console.log("connection string : " + connectionString);
mongoose.connect(connectionString);

// Setup server
var app = express();
var httpsOptions = {
    key: fs.readFileSync('../server/privatekey.pem'),
    cert: fs.readFileSync('../server/certificate.pem')
};
var baseAddress = 5000;
var redirectAddress = 5001;
var httpsAddress = 5002;

net.createServer(tcpConnection).listen(baseAddress);
http.createServer(httpConnection).listen(redirectAddress);
https.createServer(httpsOptions, httpsConnection).listen(httpsAddress);

function tcpConnection(conn) {
    conn.once('data', function (buf) {
        // A TLS handshake record starts with byte 22.
        var address = (buf[0] === 22) ? httpsAddress : redirectAddress;
        var proxy = net.createConnection(address, function () {
            proxy.write(buf);
            conn.pipe(proxy).pipe(conn);
        });
    });
}

function httpConnection(req, res) {
    var host = req.headers['host'];
    res.writeHead(301, { "Location": "https://" + host + req.url });
    res.end();
}

function httpsConnection(req, res) {
    res.writeHead(200, { 'Content-Length': '5' });
    res.end('HTTPS');
}

// Expose app
exports = module.exports = app;
回答如下:

因为您正在尝试连接到端口

5000
,而您的应用程序正在侦听端口
3000
.

发布评论

评论列表(0)

  1. 暂无评论