Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write Procfile for node.js heroku deployment using bin/www?

Tags:

express

heroku

I am trying to deploy a Heroku app, and I believe the procfile may be the reason my app is not deploying. I've tried multiple solutions including:

web: node ./bin/www web: npm start

There may be another reason my app is not working, but I want to make sure my Procfile is set up correctly

like image 937
Brian Ly Avatar asked Feb 26 '16 23:02

Brian Ly


People also ask

What does Procfile do in Heroku?

Procfile is a file that specifies the commands that are executed. by an Heroku app on startup. While it is not necessary to include a Procfile. for Heroku deployment, a Procfile allows for more startup configuration. and the definition of multiple processes that run separate dynos.

What is Procfile in Nodejs?

Define a Procfile Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app. The Procfile in the example app you deployed looks like this: web: npm start. This declares a single process type, web , and the command needed to run it.


2 Answers

You should do:

web: ./bin/www npm start

This is what fixed it for me!

like image 134
frogbandit Avatar answered Oct 02 '22 05:10

frogbandit


This is what I have:

  1. A file in the root directory of the project called Procfile (no file extension)
  2. Inside the file, the first line reads web: bin/web
  3. In the bin directory which is also located in the rood directory of the project, I have a file called web and inside I have node ./bin/www (well I have more, but lets keep it simple).
  4. there is another file in the bin directory called www where I have the code to start the node server.
  5. Both files in the bin directory needs to be executable, and you can set this by doing chmod +x file_name

Explanation for the Procfile

As mentioned above, in the Procfile I have this line: web: bin/web where

  1. web: - is the name of the process, and needs to be web for Heroku to like you :)
  2. bin/web - is the path to your file

I hope this helps :)

like image 28
David Gatti Avatar answered Oct 02 '22 05:10

David Gatti