Deploying NodeJS App on Heroku
Monday, August 8th, 2016
The need for back-end APIs is ever increasing with the rise of connected mobile apps. Developers require tools that help them prototype rapidly and also allow them to build software with a low budget. I found that Heroku allows developers to deploy quickly and it is also economically viable even for smaller projects or to prototype.
Select NodeJS from the options and click 'Save changes'.
Step 6
Add Procfile to the local Angular app we created earlier.
Open the Procfile in any text editor and paste the following lines.
Step 7
Copy the values for 'devdependencies' in package.json file of your local NodeJS app to the 'dependencies' object.
Open gulpfile.js of your local app and replace line 141 with the following line. This is because heroku assigns port automatically.
Commit code with message "init".
Step 10
Push to heroku and view the app on browser by visiting sampleappjs.herokuapp.com.
Step 2
Install heroku tools from https://toolbelt.heroku.com/.
Step 3
Create a NodeJS app locally on your pc/mac. I will create a sample Angular app using slushjs and the NodeJS server will load the routes.
root@ubuntu:~/Desktop/sampleApp# gulp serve
Step 4
Create a new app on heroku dashboard by clicking New > Create app. You can call this app anything you want but for this tutorial I will call it 'sampleappjs'.Step 5
Add NodeJS to heroku app. Go to Settings > Add buildpack on heroku app page.Step 6
Add Procfile to the local Angular app we created earlier.
root@ubuntu:~/Desktop/sampleApp# touch Procfile
Open the Procfile in any text editor and paste the following lines.
web: gulp serve
Step 7
Copy the values for 'devdependencies' in package.json file of your local NodeJS app to the 'dependencies' object.
Step 8
Open gulpfile.js of your local app and replace line 141 with the following line. This is because heroku assigns port automatically.
port: process.env.PORT || 3000,
Step 9
Add remote origin to local app by copying the Git URL from heroku app settings page.Commit code with message "init".
Step 10
Push to heroku and view the app on browser by visiting sampleappjs.herokuapp.com.
And this is how you can push a NodeJS app to heroku.