Node.js samples for Google Cloud Platform products.
JavaScript Shell Other
Clone or download
Permalink
Failed to load latest commit information.
.kokoro Remove tasks samples (#703) Aug 3, 2018
appengine remove unappropriated warning (#704) Aug 15, 2018
auth Delete Kokoro tests that fail locally (#655) Jun 13, 2018
bigquery Move bigquery and vision samples. (#535) Dec 12, 2017
cloudtasks Remove tasks samples (#703) Aug 3, 2018
computeengine Remove compute samples which have moved. (#514) Oct 31, 2017
containerengine Fix failing tests (#683) Jul 12, 2018
datastore Move datastore samples. (#552) Jan 12, 2018
debugger Migrate tests to Kokoro (#652) Jun 12, 2018
dlp Remove DLP samples which have moved. (#515) Nov 1, 2017
dns Remove samples that have moved elsewhere. (#504) Oct 24, 2017
endpoints Fix failing tests (#683) Jul 12, 2018
error-reporting Migrate tests to Kokoro (#652) Jun 12, 2018
functions GCF: Headless Chrome sample (#705) Aug 9, 2018
iot Adds packages used by manager and test runner. (#702) Aug 2, 2018
jobs/cjd_sample Check in Cloud Job Discovery quick start (#684) Jul 17, 2018
kms Generalizing kms samples for GCS docs (#708) Aug 13, 2018
language Fix failing tests (#683) Jul 12, 2018
logging Remove samples that have moved elsewhere. (#504) Oct 24, 2017
memorystore/redis Fixing GCE deployment script for Cloud Memorystore (#707) Aug 10, 2018
monitoring Remove samples that have moved elsewhere. (#504) Oct 24, 2017
pubsub Move pubsub samples. (#554) Jan 12, 2018
resource Delete samples that have moved. (#518) Nov 6, 2017
scripts chore: update (most) dependencies + (some) samples (#583) Mar 28, 2018
spanner Delete spanner,translate,video samples, which have moved. (#512) Oct 30, 2017
speech Delete samples that have moved. (#518) Nov 6, 2017
storage-transfer Migrate tests to Kokoro (#652) Jun 12, 2018
storage Remove samples that have moved elsewhere. (#504) Oct 24, 2017
trace Migrate tests to Kokoro (#652) Jun 12, 2018
translate Delete spanner,translate,video samples, which have moved. (#512) Oct 30, 2017
video Delete spanner,translate,video samples, which have moved. (#512) Oct 30, 2017
vision Move bigquery and vision samples. (#535) Dec 12, 2017
.gitignore Build updates. (#462) Aug 23, 2017
.travis.yml Travis: fix failing tests + update dependencies (#335) Apr 5, 2017
CODE_OF_CONDUCT.md chore: run repo-tools generate (#638) Jun 5, 2018
CONTRIBUTING.md Fix CONTRIBUTING.md links not rendering correctly (#389) May 15, 2017
CONTRIBUTORS chore: run repo-tools generate (#638) Jun 5, 2018
LICENSE chore: run repo-tools generate (#638) Jun 5, 2018
README.md Delete Prediction API samples. (#656) Jun 14, 2018
circle.yml Export variable for storage bucket (#668) Jun 19, 2018
key.json.enc Change key files. Aug 5, 2016
package-lock.json chore: run repo-tools generate (#638) Jun 5, 2018
package.json chore: run repo-tools generate (#638) Jun 5, 2018

README.md

Google Cloud Platform logo

Google Cloud Platform Node.js Samples Slack Build Coverage

Node.js samples for Google Cloud Platform products.

See cloud.google.com/nodejs to get up and running with Node.js on Google Cloud Platform.

Table of Contents

Setup

Prerequisites

  1. Install Node.js v4.5.0 or greater

  2. Clone this repository:

     git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git
    
  3. Change directory in to the project:

     cd nodejs-docs-samples
    
  4. Set the GCLOUD_PROJECT environment variable:

    Linux:

     export GCLOUD_PROJECT=your-project-id
    

    Windows:

     set GCLOUD_PROJECT=your-project-id
    

    Windows (PowerShell):

     $env:GCLOUD_PROJECT="your-project-id"
    
  5. Obtain authentication credentials.

    Create local credentials by running the following command and following the oauth2 flow (read more about the command here):

     gcloud auth application-default login
    

    In non-Google Cloud environments, GCE instances created without the correct scopes, or local workstations where the gcloud beta auth application-default login command fails, use a service account by doing the following:

    • Go to API Manager -> Credentials
    • Click "New Credentials", and create a service account or click here
    • Download the JSON for this service account, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the file containing the JSON credentials.

    Set the GOOGLE_APPLICATION_CREDENTIALS environment variable:

    Linux:

     export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json
    

    Windows:

     set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json
    

    Windows (PowerShell):

     $env:GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account_file.json"
    

    Note for code running on GCE, GAE, or other environments:

    On Google App Engine, the credentials should be found automatically.

    On Google Compute Engine, the credentials should be found automatically, but require that you create the instance with the correct scopes.

     gcloud compute instances create --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/compute.readonly" test-instance
    

    If you did not create the instance with the right scopes, you can still upload a JSON service account and set GOOGLE_APPLICATION_CREDENTIALS as described.

    Read more about Google Cloud Platform Authentication.

    Note for running unit tests:

    Install semistandard (lint tool)

How to run a sample

  1. Change directory to one of the sample folders, e.g. bigquery:

     cd bigquery/
    
  2. Install the sample's dependencies (see the sample's README for details):

     npm install
    

    or

     yarn install
    

    Note: Use npm or yarn exclusively, don't mix them.

  3. Run the sample:

     node sample_file.js [args]...
    

Client libraries

Google Cloud Platform logoGoogle Cloud Node.js client library

The recommended, idiomatic client for Google Cloud Platform services.

Google logoGoogle API Node.js client library

An older Node.js client library for making REST requests to Google APIs. Use this for Google Cloud APIs that are not yet supported by the Google Cloud Node.js client library.

Code samples

Compute

Google App Engine

Google App Engine is a fully managed serverless application platform.

View the App Engine Node.js samples.

Google Compute Engine

Compute Engine lets you create and run virtual machines on Google infrastructure.

View the Compute Engine Node.js samples.

Google Container Engine

Container Engine: Run Docker containers on Google Cloud Platform, powered by Kubernetes.

View the Container Engine Node.js samples.

Google Cloud Functions (Beta)

Cloud Functions is a lightweight, event-based, asynchronous compute solution that allows you to create small, single-purpose functions that respond to Cloud events without the need to manage a server or a runtime environment.

View the Cloud Functions Node.js samples.

Storage and Databases

Cloud Spanner

Cloud Spanner is a managed, mission-critical, globally consistent and scalable relational database service.

View the Cloud Spanner Node.js samples.

Google Cloud Datastore

Cloud Datastore is a NoSQL document database built for automatic scaling, high performance, and ease of application development.

View the Cloud Datastore Node.js samples.

Google Cloud Storage

Cloud Storage allows world-wide storage and retrieval of any amount of data at any time.

View the Cloud Storage JSON API Node.js Client samples.

Google Cloud Storage Transfer API

The Google Cloud Storage Transfer API allows you to quickly import online data into Google Cloud Storage.

View the Cloud Storage Transfer API Node.js samples.

Big Data

Google BigQuery

BigQuery is Google's fully managed, petabyte scale, low cost analytics data warehouse.

View the BigQuery Node.js samples.

Google Cloud Pub/Sub

Cloud Pub/Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

View the Cloud Pub/Sub Node.js samples.

Machine Learning

Google Cloud Natural Language API

Cloud Natural Language API provides natural language understanding technologies to developers, including sentiment analysis, entity recognition, and syntax analysis. This API is part of the larger Cloud Machine Learning API.

View the Cloud Natural Language API Node.js Client samples.

Google Cloud Speech API (Beta)

The Cloud Speech API enables easy integration of Google speech recognition technologies into developer applications.

View the Cloud Speech API Node.js samples.

Google Translate API

With the Google Translate API, you can dynamically translate text between thousands of language pairs.

View the Translate API Node.js samples.

Google Cloud Video Intelligence API

The Cloud Video Intelligence API allows developers to use Google video analysis technology as part of their applications.

View the Cloud Video Intelligence API Node.js samples.

Google Cloud Vision API

The Cloud Vision API allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.

View the Cloud Vision API Node.js samples.

Management Tools

Stackdriver Debugger

Stackdriver Debugger makes it easier to view the application state without adding logging statements.

View the Stackdriver Debugger Node.js sample.

Stackdriver Logging

Stackdriver Logging allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services.

View the Stackdriver Logging API Node.js Client samples.

Stackdriver Monitoring

Stackdriver Monitoring collects metrics, events, and metadata from Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, application instrumentation, and a variety of common application components including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others.

View the Stackdriver Monitoring API Node.js Client samples.

Stackdriver Trace

Stackdriver Trace is a distributed tracing system for Google Cloud Platform that collects latency data from App Engine applications and displays it in near real time in the Google Cloud Platform Console.

View the Stackdriver Trace Node.js sample.

Networking

Google Cloud DNS

Publish your domain names using Google's infrastructure for production-quality, high-volume DNS services. Google's global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world. Read more about Google Cloud DNS.

View the Google Cloud DNS API Node.js Client samples.

Identity and Security

Google Cloud Key Management Service

The Data Loss Prevention API provides programmatic access to a powerful detection engine for personally identifiable information and other privacy-sensitive data in unstructured data streams.

View the Google Cloud Data Loss Prevention API Node.js samples.

Google Cloud Key Management Service

The Cloud KMS API is a service that allows you to keep encryption keys centrally in the cloud, for direct use by cloud services.

View the Google Cloud Key Management Service Node.js samples.

Other sample applications

Bookshelf tutorial app

The Bookshelf app is a sample web app written in Node.js that shows you how to use a variety of Google Cloud Platform features.

View the tutorial or the source code.

LabelCat

LabelCat is a NodeJS app that uses the Google Cloud Prediction API to automatically label GitHub Issues as they are created.

View the tutorial or the source code.

Node.js Codelab

In the Node.js Web App Google Cloud Platform codelab, you learn how to integrate Google Cloud Platform services into a Node.js web application to store data, upload images, and authenticate users.

View the tutorial or the source code.

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE