简体   繁体   中英

Can't run Node.js app on Heroku

I have created small app which is using Node.js on backend and Angular.js. Locally it's working fine without error. When I deployed it to Heroku I have get these from logs :

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

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

server.js file

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:

app.listen(process.env.PORT);

I can't see it in your code.

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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