简体   繁体   English

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

[英]Can't run Node.js app on Heroku

I have created small app which is using Node.js on backend and Angular.js. 我创建了是在后台和Angular.js使用Node.js的小应用程序。 Locally it's working fine without error. 在本地,它工作正常,没有错误。 When I deployed it to Heroku I have get these from logs : 当我将其部署到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 file Package.json文件

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

server.js file 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 directory structure 应用目录结构 应用目录结构

You need to start listening on the Express app: 您需要开始在Express应用上收听:

app.listen(process.env.PORT);

I can't see it in your code. 我在您的代码中看不到它。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM