Blog Engineering Deploy a NodeJS Express app with GitLab's Cloud Run integration
Published on: January 13, 2025
3 min read

Deploy a NodeJS Express app with GitLab's Cloud Run integration

This tutorial will show you how to use NodeJS and Express to deploy an application to Google Cloud. This step-by-step guide will have you up and running in less than 10 minutes with the Cloud Run integration.

speedlights.png

Are you looking to deploy your NodeJS app to Google Cloud with the least maintenance possible? This tutorial will show you how to utilize GitLab’s Google Cloud integration to deploy your NodeJS app in less than 10 minutes.

Traditionally, deploying an application often requires assistance from production or DevOps engineers. This integration now empowers developers to handle deployments independently. Whether you’re a solo developer or part of a large team, this setup gives everyone the ability to deploy their applications efficiently.

Overview

  • Create a new project in GitLab
  • Set up your NodeJS application
  • Use the Google Cloud integration to create a Service account
  • Use the Google Cloud integration to configure Cloud Run via Merge Request
  • Enjoy your newly deployed Java Spring Boot app
  • Follow the cleanup guide

Prerequisites

  • Owner access on a Google Cloud Platform project
  • Working knowledge of JavaScript/TypeScript (not playing favorites here!)
  • Working knowledge of GitLab CI
  • 10 minutes

Step-by-step guide

1. Create a new project in GitLab

We decided to call our project nodejs–express-cloud-run for simplicity.

Create a new project

2. Upload your NodeJS app or use this example to get started.

Demo

Note: Make sure to include the cloud-run CI template within your project.

cloud-run CI template include

3. Use the Google Cloud integration to create a Service account.

Navigate to Operate > Google Cloud > Create Service account.

Create Service account screen

Also configure the region you would like the Cloud Run instance deployed to.

Cloud Run instance deployment region selection

4. Go to the Deployments tab and use the Google Cloud integration to configure Cloud Run via Merge Request.

Deployments - Configuration of Cloud Run via Merge Request

This will open a merge request – immediately merge it.

Merge request for deployment

Note: GCP_PROJECT_ID, GCP_REGION, GCP_SERVICE_ACCOUNT, and GCP_SERVICE_ACCOUNT_KEY will all be automatically populated from the previous steps.

Variables listing

5. Voila! Check your pipeline and you will see you have successfully deployed to Google Cloud Run using GitLab CI.

Successful deployment to Google Cloud Run

Click the Service URL to view your newly deployed Node server.

View newly deployed Node server

In addition, you can navigate to Operate > Environments to see a list of deployments for your environments.

Environments view of deployment list

By clicking on the environment called main, you’ll be able to view a complete list of deployments specific to that environment.

Main view of deployments to specific environment

6. Next steps

To get started with developing your Node application, try adding another endpoint. For instance, in your index.js file, you can add a /bye endpoint as shown below:

app.get('/bye', (req, res) => {
  res.send(`Have a great day! See you!`);
});

Push the changes to the repo, and watch the deploy-to-cloud-run job deploy the updates. Once it’s complete, go back to the Service URL and navigate to the /bye endpoint to see the new functionality in action.

Bye message

Follow the cleanup guide

To prevent incurring charges on your Google Cloud account for the resources used in this tutorial, you can either delete the specific resources or delete the entire Google Cloud project. For detailed instructions, refer to the cleanup guide here.

Read more of these helpful tutorials from GitLab solutions architects.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback? Share your thoughts by creating a new topic in the GitLab community forum. Share your feedback

Ready to get started?

See what your team could do with a unified DevSecOps Platform.

Get free trial

Find out which plan works best for your team

Learn about pricing

Learn about what GitLab can do for your team

Talk to an expert