This folder contains the sample code for the Structured data tutorial. Please refer to the tutorial for instructions on configuring, running, and deploying this sample.
Install Node.js.
- Optional: Install Yarn.
Install git.
Create a Google Cloud Platform project.
Install the Google Cloud SDK.
After downloading the SDK, initialize it:
gcloud init
Acquire local credentials for authenticating with Google Cloud Platform services:
gcloud beta auth application-default loginClone the repository:
git clone https://github.com/GoogleCloudPlatform/nodejs-getting-started.gitChange directory:
cd nodejs-getting-started/2-structured-dataCreate a
config.jsonfile (copied from theconfig-default.jsonfile):cp config-default.json config.json- Set
GCLOUD_PROJECTinconfig.jsonto your Google Cloud Platform project ID. - Set
DATA_BACKENDinconfig.jsonto one of"datastore","cloudsql", or"mongodb".
- Set
Install dependencies using NPM or Yarn:
Using NPM:
npm installUsing Yarn:
yarn install
Configure the backing store:
If
DATA_BACKENDis set to"cloudsql":Create a Cloud SQL instance, and download and start the Cloud SQL proxy:
Instructions for doing so: https://cloud.google.com/nodejs/getting-started/using-cloud-sql#creating_a_cloud_sql_instance
Set
MYSQL_USERinconfig.json, e.g."my-cloudsql-username".Set
MYSQL_PASSWORDinconfig.json, e.g."my-cloudsql-password".Set
INSTANCE_CONNECTION_NAMEinconfig.json, e.g."YOUR_PROJECT_ID:YOUR_REGION:YOUR_INSTANCE_ID".Run the script to setup the table:
Using NPM:
npm run init-cloudsqlUsing Yarn:
yarn run init-cloudsql
If
DATA_BACKENDis set to"mongodb":- Set
MONGO_URLinconfig.json, e.g."mongodb://username:password@123.45.67.890:27017".
- Set
Start the app using NPM or Yarn:
Using NPM:
npm startUsing Yarn:
yarn start
View the app at http://localhost:8080.
Stop the app by pressing
Ctrl+C.Deploy the app:
gcloud app deployView the deployed app at https://YOUR_PROJECT_ID.appspot.com.