Heroku+node.js错误(Web进程在启动后60秒内无法绑定到$Port)我有我的第一个node.js应用程序(在本地运行良好)-但我无法通过Heroku(第一次使用w/Heroku)部署它。代码在下面。所以不允许我编写这么多代码,所以我只想说,在我的网络中本地运行代码也没有问题。 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贡献1824条经验 获得超6个赞
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'));});
胡说叔叔
TA贡献1804条经验 获得超8个赞
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 关注
- 665 浏览
添加回答
举报
0/150
提交
取消