What is Heroku? Heroku is a fully managed container-based cloud platform, to make it easy for you to run apps written in a variety of programming languages, so in plain english, it mean you can run and deploy applications written in virtually any language, wether that be PHP, Node.js, Scala, Java or even just a simple html and css website you can do it.
Heroku also includes a free tier which is great for exploring the platform and I like to use it to run my personal portfolio projects. If you want something a bit “Beefier” meaning more power, they have other tiers that are quite affordable when comparing to services such as AWS for hosting.
Setup and Deployment
Fortunately setup and deploying your web application is crazy easy to do and according to their website you could do it in less than 10 seconds, which I can certainly agree with.
We will be using a typical Node.js Application but their documentation covers all the 1st class languages, such as PHP, Scala, Java, Ruby, Go, Closure, and of course Python.
To get started, we need to use the Heroku CLI, which they call the Heroku Toolbelt, its as simple as installing with
npm install -g heroku, preferably install the Toolbelt via the Heroku installer for Windows or using a services such as Homebrew for mac users, as npm won’t auto update the toolbelt when updates arrive, but for the purpose of this blog, the npm method is fine. For the official install documents take a look at Heroku CLI Documentation
Okay, so now we have heroku toolbelt(cli) installed we can now begin with deployment, first there are some prequites for our application which are:
Node.js and npm installed.
Make sure you have a package.json file ready and all its dependancies listed.
We need to add one important file which is the Procfile, this is a reserved file name for Heroku, and it basically tells heroku what type of application you are running and how to run it.
to do this is very simple, just add a file called “Procfile” spelled exactly as mentioned and add “web: node app.js” , and that’s it.
After you commit your changes to git, you can deploy your app to Heroku.
$ git add . $ git commit -m "Added a Procfile." $ heroku login Enter your Heroku credentials. ... $ heroku create Creating arcane-lowlands-8408... done, stack is cedar http://arcane-lowlands-8408.herokuapp.com/ | firstname.lastname@example.org:arcane-lowlands-8408.git Git remote heroku added $ git push heroku main ... -----> Node.js app detected ... -----> Launching... done http://arcane-lowlands-8408.herokuapp.com deployed to Heroku
To open the app in your browser, type
And your app is now running in a Heroku dino which is their term for a container. Every time you want to redeploy, just use git push heroku main.
Installing heroku and setup and deployment is very simple and heroku can support any web language, so its very convenient. and its free tier although is a bit slow and should not be used for an application that is expecting any traffic, its great to explore the services and to run basic applications for demo’s for example.
I typically use a combination of Heroku and Firebase to host my backend Restful api and frontend respectively. and I believe this helps with load time and performance. if you are interested in learning how to host a static frontend application, check out my other article “Deploy Static frontend sites instantly and for free with Firebase“