How to deploy LD-R on Heroku?

Heroku is a cloud Platform-as-a-Service (PaaS) supporting several programming languages among them NodeJS which can be used to deploy your LD-R instances on a scalable cloud infrastructure.

the first step is to go to Heroku website and create an account which will allow you to deploy up to 5 instances for free. Then, open your command line shell and type:

heroku login

Once logged in, you need to clone LD-R git repository:

git clone https://github.com/ali1k/ld-r.git heroku-ldr

After running the above command, you will have a clone of LD-R in heroku-ldr directory. Now, go to that directory by simply:

cd heroku-ldr

Now it is time to create an app on Heroku:

heroku create

Heroku generates a random name for your app, or you can pass a parameter to specify your own app name. Now deploy your code:

git push heroku master

The application seems to be deployed now. Ensure that at least one instance of the app is running:

heroku ps:scale web=1

Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:

heroku open

But hold on! something is wrong if you are getting an error message! Run the following command to see what went wrong:

heroku logs --tail

You can see that there are a bunch of issues when Heroku started to deploy LD-R. Let's resolve them step by step:

Heroku is a production server. So, it doesn't care about all fancy babel, webpack stuff we have put in the LD-R framework! So, we need to get rid of them by building the app first and then move the built bundles to Heroku! To build the app, you need to follow the instructions for production mode in installation page and add your desirable configs.

Now you should get all the required bundles in your 'build' folder which is initially ignored by Git. Stop the build script and as next step go to your .gitignore file and simply replace its content by:

node_modules

As Heroku is only interested in your production mode, open the 'server.js' file and hardcode the env to 'production':

//heroku
const env = 'production';

You also need to copy npm dev_dependencies to normal dependencies in package.json file.

There is only one more step left to finish the deployment preparation. You need to add a file called 'Procfile' to your repo with the following content:

web: npm start

The Procfile is a text file in the root directory of your application, to explicitly declare what command should be executed to start your app on Heroku. Now its time to test our deployment by pushing our changes to heroku branch:

git add .
git commit . -m 'LD-R is ready for deployment' --no-verify
git push heroku master

Now you should be able to visit your Heroku app URL again, be a little bit patient and then see your LD-R instance running there successfully just like what I see for my sample Heroku LD-R app: https://ldr1.herokuapp.com/ or https://ldrdemo.herokuapp.com .


Edit page on Github