DEV Community

Tony Pujals
Tony Pujals

Posted on • Updated on

Create and deploy an Express API to Cloud Run

Overview

In this article, I'm going to walk you through quickly generating either a basic starter Express API app or a simple example Express API app and deploying it to Cloud Run.

Prerequisites

See the prerequisites for using run, a lightweight CLI for creating and deploying Cloud Run apps here.

Create the app

Choose either express-api or example-express-api when asked to choose a project template. The example version demonstrates using various Express methods for a mock database.

run create
Enter fullscreen mode Exit fullscreen mode

Selecting a template
Image description

When finished
Image description

You can run the app locally, if you want.

Deploy the app

To deploy to Cloud Run, enter:

run deploy
Enter fullscreen mode Exit fullscreen mode

Since this is the first deployment, you'll be presented with a series of prompts. Your settings will be saved to a a local configuration file (run.yaml).

Note: In the current version of run, only the new project option works.

Test the app

When the deployment is finished, the run will print the URL for accessing the app.

If you chose example-express-api, the README includes instructions about testing the API using curl commands in a test script.

View app logs

To get the link to view the logs web page, enter:

run logs
Enter fullscreen mode Exit fullscreen mode

Wrapping up

The run command to delete the project when finished is not yet implemented. For now, use gcloud to delete the project using its ID (if you forget the project ID, it's stored in run.yaml).

gcloud projects delete PROJECT
Enter fullscreen mode Exit fullscreen mode

If you run into any problems, check to see if there is an issue here and, if not, please create one.

References

I provide background on run in my last article.

If you prefer to use gcloud, see this article if you need help getting started. You'll still use run to create the app from a template.

Top comments (0)