无法在Heroku上运行Node.js应用程序

时间:2014-12-30 19:19:52

标签: javascript node.js heroku

我创建了一个小应用程序,它在后端和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');
        }
    });

App目录结构 App directory structure

1 个答案:

答案 0 :(得分:2)

您需要开始收听Express应用程序:

app.listen(process.env.PORT);

我无法在您的代码中看到它。

Reference