1

Do i still to configure nginx if I want to deploy my node.js application on Heroku? or Heroku already handle that part?

If I do need to configure, what are the steps? for those of you who have experienced deploying it on heroku, could you guide me. This will be my first time deploying something for real :)

Thank you

1 Answer 1

1

Heroku handles the proxy between your app to port 80 (or SSL port when applicable) for you. But the port for your app is not fixed, it is potentially variable but always available as an Environment Variable PORT.

So in your node.js app, you should listen to process.env.PORT instead of a fixed value. Further, to make the app run both locally and on Heroku environment, you can do process.env.PORT || 3000 assuming 3000 is your choice of the port number for local development purposes.

See https://devcenter.heroku.com/articles/dynos#local-environment-variables for further details.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the answer, to handle static files Heroku will handle it alone?
@airsoftFreak can you elaborate on what you mean by handle static files? If you mean creating a server just to serve static HTML/CSS/JavaScript then you still have to go through the same process but just use the technique described here expressjs.com/en/starter/static-files.html if you use express.js
I read online that node.js isn't that good handling static files like images, and so on. While nginx is good for handling this kind of stuff.
@airsoftFreak with heroku the most "front-line" proxy is not in your hand to control. If you insist on utilizing Nginx or Apache and configure them yourself, then you better start with a VPS like digital ocean.
@airsoftFreak you don't need to configure the value of process.env.PORT, simply use it like what the answer has. And load balancing is handled for you, provided that you use more than one workers (dynos)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.