【问题标题】:Can't run Node.js app on Heroku无法在 Heroku 上运行 Node.js 应用程序
【发布时间】:2015-02-26 23:02:12
【问题描述】:

我创建了在后端和 Angular.js 上使用 Node.js 的小应用程序。在本地,它工作正常,没有错误。 当我将它部署到 Heroku 时,我从日志中得到了这些

2014-12-30T18:36:14.157309+00:00 heroku[web.1]: State changed from crashed to starting
2014-12-30T18:36:15.949841+00:00 heroku[web.1]: Starting process with command `npm start`
2014-12-30T18:36:17.059157+00:00 app[web.1]: 
2014-12-30T18:36:17.059201+00:00 app[web.1]: > contacts-app@1.1.0 start /app
2014-12-30T18:36:17.059203+00:00 app[web.1]: > node server.js
2014-12-30T18:36:17.059205+00:00 app[web.1]: 
2014-12-30T18:36:18.091349+00:00 heroku[web.1]: Process exited with status 0
2014-12-30T18:36:18.107630+00:00 heroku[web.1]: State changed from starting to crashed

Package.json 文件

{
  "name": "contacts-app",
  "version": "1.1.0",
  "description": "...",
  "author": "...",
  "scripts": {
    "start": "node server.js"
  }
}

server.js 文件

var express = require('express'),
    api     = require('./api'),
    users   = require('./accounts'),
    app     = express();

app
    .use(express.static('./public'))
    .use(users)
    .use('/api', api)
    .get('*', function (req, res) {
        if (!req.user) {
            res.redirect('/login');
        } else {
            res.sendFile(__dirname + '/public/main.html');
        }
    });

应用目录结构

【问题讨论】:

    标签: javascript node.js heroku


    【解决方案1】:

    您需要开始在 Express 应用上收听:

    app.listen(process.env.PORT);
    

    我在你的代码中看不到它。

    Reference

    【讨论】:

      猜你喜欢
      • 2012-10-12
      • 2015-11-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2017-01-31
      • 2018-04-11
      • 1970-01-01
      • 2018-12-03
      相关资源
      最近更新 更多