Alessio Breviglieri
Alessio Breviglieri

Reputation: 133

Deploying Node.js Apps on Heroku

I'm a beginner. I was tryng to deploy an "app" on Heroku but it doesn't work when going to https://peaceful-coast-7293.herokuapp.com/. It works fine with heroku local. Really don't know what else to check.

This is what I've got in my logs:

2015-12-28T10:56:44.862230+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=peaceful-coast-7293.herokuapp.com request_id=c0994f20-ef28-4cad-95ba-f861a89d698d fwd="93.33.20.213" dyno= connect= service= status=503 bytes=
2015-12-28T10:56:45.457317+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=peaceful-coast-7293.herokuapp.com request_id=a3286f8e-7051-419d-9e3d-ccb2090659c0 fwd="93.33.20.213" dyno= connect= service= status=503 bytes=

I also get those npm:

2015-12-28T11:21:07.264470+00:00 heroku[web.1]: State changed from crashed to starting
2015-12-28T11:21:08.151361+00:00 heroku[web.1]: Starting process with command `npm start`
2015-12-28T11:21:10.533548+00:00 app[web.1]: npm ERR! Linux 3.13.0-71-generic
2015-12-28T11:21:10.534886+00:00 app[web.1]: npm ERR! node v0.12.7
2015-12-28T11:21:10.534398+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2015-12-28T11:21:10.535773+00:00 app[web.1]: npm ERR! npm  v2.11.3
2015-12-28T11:21:10.536011+00:00 app[web.1]:
2015-12-28T11:21:10.536325+00:00 app[web.1]: npm ERR! missing script: start
2015-12-28T11:21:10.536603+00:00 app[web.1]: npm ERR!
2015-12-28T11:21:10.536829+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2015-12-28T11:21:10.537055+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
2015-12-28T11:21:10.544211+00:00 app[web.1]:
2015-12-28T11:21:10.544631+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2015-12-28T11:21:10.544950+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2015-12-28T11:21:11.360279+00:00 heroku[web.1]: State changed from starting to crashed
2015-12-28T11:21:11.348180+00:00 heroku[web.1]: Process exited with status 1
2015-12-28T11:35:00.705391+00:00 heroku[api]: Starting process with command `node console` by alessio.breviglieri@gmail.com
2015-12-28T11:35:02.612018+00:00 heroku[run.1521]: Awaiting client
2015-12-28T11:35:02.882034+00:00 heroku[run.1521]: State changed from starting to up
2015-12-28T11:35:32.616428+00:00 heroku[run.1521]: Error R13 (Attach error) -> Failed to attach to process
2015-12-28T11:35:33.493974+00:00 heroku[run.1521]: Process exited with status 128
2015-12-28T11:35:33.493559+00:00 heroku[run.1521]: State changed from up to complete

My app.js file:

var router = require('./router.js');
var port = process.env.PORT || 3000;

//Create a web server
var http = require('http');
http.createServer(function (request, response) {
  router.home(request, response);
}).listen(port);
console.log('Server running');

Procfile

web: node app.js

package.jsom

{
  "name": "lorem_ipsum",
  "version": "1.0.0",
  "description": "Lorem Ipsum Generator",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Alessio",
  "license": "MIT",
  "keywords": [
    "lorem",
    "ipsum"
  ],
  "engines": {
    "node": "0.12.7"
  }
}

Upvotes: 1

Views: 1458

Answers (2)

Codemaker2015
Codemaker2015

Reputation: 15699

You have to inform heroku where to start : missing script: start. In your package.json,

you should have something like this:

"scripts": {
  "start": "node app.js"
}

So your package.json will update like this,

{
  "name": "lorem_ipsum",
  "version": "1.0.0",
  "description": "Lorem Ipsum Generator",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Alessio",
  "license": "MIT",
  "keywords": [
    "lorem",
    "ipsum"
  ],
  "engines": {
    "node": "0.12.7"
  }
}

Where app.js is your entry point.

As an alternative, you can specify in Procfile:

web: node app.js

But as you mentioned the Procfile is not working. So, try with scripts start attribute.

Upvotes: 0

cloudlena
cloudlena

Reputation: 885

You need to add

"start": "node app.js"

to the "scripts" section of your package.json.

Upvotes: 2

Related Questions