Deploying Node JS code into GAE
In this post, I am going to explain to you how to install your first NodeJS application onto Google App Engine, before getting started you need to have Google Cloud SDK on your machine.
Following steps shows you how to install it.
Installation:
on ubuntu:
$ export CLOUD_SDK_REPO=”cloud-sdk-$(lsb_release -c -s)"
$ echo "deb http://packages.cloud.google.com/apt
$CLOUD_SDK_REPO main" | sudo tee -a
etc/apt/sources.list.d/google-cloud-sdk.list
$ curl https://packages.cloud.google.com/apt/doc/apt-####
key.gpg | sudo apt-key add -
For other platforms, you can get details here
https://cloud.google.com/sdk/docs
Download/clone the repository from GitHub
Link to download code
https://github.com/GoogleCloudPlatform/nodejs-docs-samples
** Or clone the repository by using git **
** Git clone ** https://github.com/GoogleCloudPlatform/nodejs-docs-samples
** To install all modules/dependencies of the project **
$ npm install
Running project locally
$ npm start / node index.js
Deploying to App Engine
$ Npm run deploy / gcloud app deploy
Environment setup:
There are two environments available in App Engine they are
- Flexible
- Standard
To find differences between these two environments follow the link
https://cloud.google.com/appengine/docs/the-appengine-environments
If you want to deploy your application in the standard environment
- In the project, you will find the ** app.yaml ** file.
- Need to mention the environment and instance in this file
App.yaml file for standard environment
runtime: nodejs 8
instance_class: F2
** App.yaml file for flexible environment **
runtime: nodejs
api_version: '1.0'
env: flexible
threadsafe: true
automatic_scaling:
min_num_instances: 1
max_num_instances: 1
cpu_utilization:
target_utilization: 0.5