A simple demo on CI/CD by deploying a Node app to Heroku. It is fast and easy to develop by using Express, a minimal and flexible node.js web application framework and deployed it to Heroku.
GitHub integration and automatic deploys are enabled as Heroku has registered a webhook on GitHub repo. Heroku will auto deploy in real time when any changes committed at GitHub.
-
Create a folder ilearn-git on your local machine.
-
Add a file package.json and paste the same code.
-
Add a file app.js and paste the same code.
-
Run the following commands.
npm install --save express body-parser
node app.js
-
Node will start the server and show the below message.
-
Test the Node app using Postman. Import Curl statement.
Curl localhost:3000
-
It will show the below message in the response body.
Cool! A simple Nodejs app is created successfully.
-
Create a new public repository ilearn-git on Github. It is a remote repo.
-
Initialize the Git repository in the command prompt at your local machine.
git init
-
Add all the files to your local Git (staging).
git add .
-
Commit your code changes to your local Git.
git commit -m "first commit"
-
Link to GitHub repository (i.e. remote repo).
git remote add origin https://github.com/jack1yn/ilearn-git.git
-
Push the changes to GitHub repository (i.e. main).
git push origin main
-
Check the status. It will show the below message.
git status
- Open GitHub and refresh the repository. Check that the changes is updated to the remote repo.
- Open the Heroku app.
- Click New and select Create new app with name ilearnapp.
- Open Deploy tab at dashboard of Heroku app.
- Select Github as the deployment method by selecting Connect to GitHub option.
- Key in "ilearn-git" and select Connect. It will find and connect to Github repo.
- Select Enable Automatic Deploys. Heroku will pick up the changes at Github and deploy automatically.
- Go to Settings tab and click Add buildpack.
- Select nodejs from the options and click Save changes.
- Go back to Deploy tab and click Deploy Branch at the bottom.
- Go to Settings tab. Copy and paste the URL ilearnapp.herokuapp.com in the browser.
Below message will be shown in the browser.
Great! A simple web applicaion is created that can be accessed over the internet.
Now make some code changes at your Git repo and see the changes deployed automaically at Heroku.
- Simple web application architecture
- Rapid deployment
- Easy to understand
- Node on your local machine
- GitHub account to host the code online
- GitHub desktop to push the code changes to Github
- Heroku account to deploy the app
- Docker Hub to push container images to Docker Hub
- How to get started with GIT and work with GIT Remote Repo
- Use the GitHub Desktop client
- How To Stage Commits And Push To Github With Visual Studio Code
- Heroku Dev Guide
- Learn Docker
- Get started with Git and Docker
- Understand the concept of DevOps and CI/CD
- Practice is key to success