Deploying Swagger Documentation on Google Cloud
In the second article in this series, we explained how to deploy your Node.js application and documentation to Railway. This third article in the series will focus on deploying your Node.js application and documentation to Google Cloud.
Prerequisites:
- Google Cloud Platform Account: You will need a Google Cloud Platform (GCP) account. If you don't have one, you can sign up for a free trial.
- Google Cloud SDK: Install the Google Cloud SDK on your local machine. You can download it from Google Cloud SDK Downloads.
Create an app.yaml
Configuration File:
Create an app.yaml
file in your project's root directory to configure your Google App Engine deployment.
runtime: nodejs14
env_variables:
NODE_ENV: production
handlers:
- url: /api-docs
static_dir: public
- url: /.*
script: auto
This configuration file specifies that we're using Node.js 14, sets the NODE_ENV
environment variable to "production," and configures handlers for your application.
Create a .gcloudignore
File:
Create a .gcloudignore
file in your project's root directory to specify files and directories to be ignored when deploying to Google App Engine. Here's a sample .gcloudignore
file:
This ensures that Git metadata and node_modules
are excluded from your deployment.
Deploy to Google App Engine:
To deploy your app to Google App Engine, open your command line interface, navigate to your project's root directory, and run the following command:
gcloud app deploy
This command will guide you through the deployment process, including selecting a project and region. Once the deployment is complete, your app will be live on Google App Engine.
Access Your Swagger Documentation:
You can access your Swagger documentation on Google App Engine by navigating to:
https://YOUR_PROJECT_ID.REGION_ID.r.appspot.com/api-docs
Replace YOUR_PROJECT_ID
with your Google Cloud Project ID and REGION_ID
with the region where you deployed your app.
That's it! You've now deployed your Node.js app with Swagger documentation on Google Cloud using Google App Engine. Your documentation is publicly accessible on Google App Engine's URL.