2014-12-30 72 views
1

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

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]: > [email protected] 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 directory structure

回答

2

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

app.listen(process.env.PORT); 

我在代码中看不到它。

Reference

相关问题