慕標(biāo)琳琳
2019-07-11 15:52:28
Heroku+node.js錯(cuò)誤(Web進(jìn)程在啟動(dòng)后60秒內(nèi)無(wú)法綁定到$Port)我有我的第一個(gè)node.js應(yīng)用程序(在本地運(yùn)行良好)-但我無(wú)法通過(guò)Heroku(第一次使用w/Heroku)部署它。代碼在下面。所以不允許我編寫這么多代碼,所以我只想說(shuō),在我的網(wǎng)絡(luò)中本地運(yùn)行代碼也沒(méi)有問(wèn)題。 var http = require('http');
var fs = require('fs');
var path = require('path');
http.createServer(function (request, response) {
console.log('request starting for ');
console.log(request);
var filePath = '.' + request.url;
if (filePath == './')
filePath = './index.html';
console.log(filePath);
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'text/javascript';
break;
case '.css':
contentType = 'text/css';
break;
}
path.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}
else {
response.writeHead(404);
response.end();
}
});
}).listen(5000);
console.log('Server running at http://127.0.0.1:5000/');知道嗎?
3 回答

慕妹3242003
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
server.listen(config.port, config.ip, function () { console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));});
server.listen(config.port, function () { console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));});

胡說(shuō)叔叔
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊
server.listen(port, [host], [backlog], [callback])
.
.listen(process.env.PORT)
.listen(process.env.PORT, '0.0.0.0')
var server_port = process.env.YOUR_PORT || process.env.PORT || 80;var server_host = process.env.YOUR_HOST || '0.0.0.0';server.listen(server_port, server_host, function() { console.log('Listening on port %d', server_port);});
- 3 回答
- 0 關(guān)注
- 718 瀏覽
添加回答
舉報(bào)
0/150
提交
取消