Developing a Heroku NodeJs project on GitHub Codespaces

Cloud Architect
4 min readMar 8, 2022

I’ve written about using GitHub Codespaces to develop for Salesforce in the Cloud. Heroku can require more development tools and libraries than Salesforce, and as such is also a good candidate for running in an ‘on demand’ cloud development service such as GitHub Codespaces.

I’m going to demonstrate how to build a Heroku web service completely with CodeSpaces and NodeJs. Other languages for Heroku probably can be made to work with a similar process.

  1. Create GitHub Repository
  2. Specify .gitignore with Node settings
  3. Create and open ‘New Codespace’

4. In the VS Code terminal install Heroku tools with the following script:

curl https://cli-assets.heroku.com/install.sh | sh

5. Credentials to log into Heroku. Browser based login doesn’t work (with MFA).Find your Heroku API Key in your Heroku Account settings:

6. Create a new file called ~/.netrc with the nano text editor (note this file will stay in your CodeSpace but not be part of your source code — Link to details ).

7. Create the file below with your Heroku username and API Key for both credentials. (control-X to leave. Choose to Save!)

8. Return to your Workspace directory:

9. Stop and restart your CodeSpace:

10. Create Node JS project:

  • npm init (Note: use whatever parameters you want. I used ‘server.js’ as the ‘main’ parameter. You can change later in Package.json)
  • Create server.js in the base directory
  • Install Express: npm install — save express
  • Create a basic app:

9. Run the node server:

  • node server.js
  • Optional — Click ‘Open in Browser’ in the popup
  • This will open a new browser tab, with a your request given back to you
  • Quit the server with control-c key combination

10. Deploy to Heroku

  • Create a Procfile file (case sensitive, no suffix)
  • Add the startup path

11. Create the Heroku app:

12. Push changes to GitHub

13. Push changes to Heroku:

14. Check App is deployed by invoking service from another browser tab:

Notes:

  1. Victoria Lo’s great blog series helped me with the process of creating a basic Heroku app with NodeJs: https://lo-victoria.com/build-rest-api-with-nodejs-design-and-plan-restful-api
  2. I’m on the GitHub Codespace beta. I believe new users would need to ‘pay as you go’ — see prices here: https://github.com/features/codespaces
  3. You can connect to your Codespace through a locally installed VS Code, however running the browser to the app doesn’t seem to work as well
  4. Remember that the terminal is running in a Linux Ubuntu container. Commands and environments will be different to Windows and Mac
  5. Heroku can also integrate with GitHub. You could set that up if you wanted

--

--