Marek Dlugos
Marek Dlugos

Reputation: 197

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

Upvotes: 1

Views: 320

Answers (1)

mcont
mcont

Reputation: 1933

You need to start listening on the Express app:

app.listen(process.env.PORT);

I can't see it in your code.

Reference

Upvotes: 2

Related Questions