This lab builds upon the previous lab. For this lab the task was to extend the previous lab’s code to include cloud PaaS deployment.
I needed to create a simple node.js web server and REST API that uses the Seneca module that was created in the previous labs. I than needed to deploy the server to run on the cloud hosting platform Heroku.
My GitHub repository is available here: https://github.com/badrmodoukh/Seneca2017LearningLab
My Heroku app URL is: https://protected-island-21203.herokuapp.com/
Steps I took to complete this lab:
I first created a node.js web server using express. This provided an HTTP based API for calling the Seneca module functions. I named the file server.js. This is the code in the file:
I than tested the server locally by running node server.js.
This enabled me to navigate to the routes I created which are:
- http://localhost:3000/ – (this route displays a simple message “My Server is Working!”)
- http://localhost:firstname.lastname@example.org – (this route returns a JSON formatted response indicating that the given email is valid or invalid)
- http://localhost:3000/format/badr – (this route returns a JSON formatted response with the given name formatted as a valid Seneca email address)
- http://localhost:3000/healthcheck – (this route returns a JSON formatted response with the server’s uptime)
After I tested locally and everything seemed to work properly I needed to deploy to Heroku. I install Heroku and was able to interact with it using the command line. I created a Procfile that informs Heroku which command to run when it starts the app.
After creating the Procfile I needed to add, commit, and push the code onto GitHub.
Once the code was on GitHub I than started the process of deploying the app onto Heroku. The commands I used to do this were:
- heroku create – this creates a new app and generates a random name for the app
- git push heroku master – this is used to push the code to the heroku remote that was created
- heroku ps:scale web=1 – this starts one web server with the code I pushed
- heroku open – this is used to open the app that was deployed to heroku
After doing these steps the app was running on Heroku.
Overall, doing this lab was quite interesting. I never used Heroku before and I found it fun and important learning how to use it. I liked the way Heroku works with Git making it easier to deploy code. I can see now why it is so important to run your code on cloud infrastructure like Heroku to test your work especially REST APIs. I will definitely consider using this in the future.