Deploying Rails and Nodejs

I wrote a live web application consisting of the following:

  • Rails for serving web pages (listening on port 80)
  • Nodejs handles realtime logic (listening on port 8888)

This way, on the specific page served by my rails app, the JS will use to establish a connection to my nodejs instance to allow realtime HTTP push.

Currently Nodejs communicates with Rails by simply updating the rails database. (I know this is a ghetto , but it works).

What are my deployment options?

  • I used to deploy simple web applications to heroku and I really like the simplicity.
  • I have also deployed a web app with similar functionality (besides one consisting of django + nodejs). I used HAProxy for reverse proxying to handle routing traffic to the correct process on my machine. However, I have deployed this to a VPS server.

Note: the ugliness is likely to revolve around:

  • I rely on shared db
  • These processes are listening on different ports

source to share

2 answers

We had this exact problem. We deployed them to split Heroku apps, but kept them in the same codebase. describes how to do this.

Custom script in bin / web


if [ "$RAILS_DEPLOYMENT" == "true" ]; then
  bundle exec rails server -p $PORT
  node node/index.js


And the Procfile:

web: bin/web




I would consider installing these two applications as separate Heroku applications on different subdomains and just both of them on port 80. The communication between them goes through a common database, so they don't need to be on the same machine or even Data Center. supports cross-domain requests in all browsers, so this shouldn't cause any problems.



All Articles