Skip to content

cortl/express-gcp

Repository files navigation

Node.js/Express Boilerplate for GCP 🐣

Github Actions Size License

About

Boilerplate application for Node/Express on Google Cloud App Engine

Getting Started

Prerequisites

Google Cloud Platform project setup and the Google Quickstart "Before You Begin" steps followed.

You'll also need to change the projectId in /config/default.js to your Google project id.

Installing

  1. npm install

Usage & Developing

  1. npm run dev
  2. Develop! 🎉
  3. npm run verify to ensure your changes didn't break anything!

Testing

We prefer to use [Mocha] combined with [Sinon] and [Chance] to unit test our applications. You can auto-run the tests using a tool called [Nodemon] which will auto-run the tests. Some helpful commands to use when you want to run a specfic set of tests are

nodemon --watch test --exec "Describe Block"

for this sample project you could use nodemon --watch test --exec "Index Router" which would run all the tests under

describe('Index Router', () => {
    test('should run this test', () => {});

    describe('GET /', () => {
        test('should also run this test', () => {});
    });
});

Logging

Logs for this application can be found in your GAE log page. There aren't many options for logging to Google Cloud that are still actively maintained other than the @google-cloud/logging package, so this project takes advantage of that. It follows the same interace as console so it won't be hard to swap to.

Deploying

  1. gcloud app deploy
  2. gcloud app browse

Github Actions

Create a service account that you'll use to deploy the application with after it has been built. It will need the following IAM roles:

  • App Engine Admin
  • Cloud Build Editor
  • Storage Admin
  • Service Account User

After you've downloaded the credentials, copy the entire contents into an environment variable called GCP_SA_KEY in your repositories' actions' secrets.

The first build in Github Actions will fail and it will tell you to enable the App Engine Admin API, do that and re-run