相关疑难解决方法(0)

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 { …
Run Code Online (Sandbox Code Playgroud)

heroku node.js

408
推荐指数
10
解决办法
17万
查看次数

Heroku/Nodejs 启动失败,at=error code=H10 desc="App

我知道这已经被问过几次了,但我还没有找到有效的解决方案。我正在尝试将我的节点服务器部署在 Heroku 上并成功构建,但日志会打印以下消息。我也在使用猫鼬并且在本地部署没有问题。

2019-02-10T22:30:09.912634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=chatifydotcom.herokuapp.com request_id=b486e511-ff21-4166-ae1d-07bf5796691e fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https
Run Code Online (Sandbox Code Playgroud)

2019-02-10T22:30:10.287542+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=chatifydotcom.herokuapp.com request_id= 18f17ca0-56df-4dfe-a560-d890a699f17f fwd="74.196.2.211" dyno=connect=service=status=503 bytes=protocol=https

服务器.js

 const uri = process.env.MONGODB_URI || "mongodb://localhost:27017/chat"
mongoose
  .connect(uri, { useNewUrlParser: true })
  .then(() => console.log("MongoDB Connected"))
  .catch(err => console.log(err.message))

    const port = process.env.PORT || 9000
server.listen(port, () => {
  console.log(`This server is over ${port}`)
})
Run Code Online (Sandbox Code Playgroud)

heroku mongodb node.js

3
推荐指数
1
解决办法
5742
查看次数

标签 统计

heroku ×2

node.js ×2

mongodb ×1