Skip to content

A simple microservice as an example for running Node.js on Google Cloud Run

License

Notifications You must be signed in to change notification settings

humanwhocodes/hello-nodejs-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello Node.js Service

by Nicholas C. Zakas

If you find this useful, please consider supporting my work with a donation.

Description

A simple Fastify server intended to serve as an example of deploying a Node.js application to Google Cloud Run.

Usage

After cloning the repository, install the dependencies:

$ npm install

To start the server, run:

$ npm start

Locally, this will run the server on http://localhost:8080.

To run inside a Docker container, download the pack CLI and then run:

$ pack build app --builder gcr.io/buildpacks/builder
$ docker run -it --init -p 8080:8080 -e PORT=8080 app

Notes

  1. The server reads from the PORT environment variable to determine which port to listen on. This is important because Google Cloud Run defines this variable and it's the only port that will be open.
  2. Google Cloud Run also requires that the server listen on 0.0.0.0 because 127.0.0.1 is a loopback address with no external access.
  3. You no longer need to define a Dockerfile to run Node.js projects on Google Cloud Run. You can instead use the built-in Node.js Buildpack. All you need to do is define npm start.

License

Apache 2.0

About

A simple microservice as an example for running Node.js on Google Cloud Run

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published