Getting started with Node.js
Get up and running with Node.js on Google Cloud Platform
Node.js starter projects
These step-by-step guides will show you how to get your first Node.js app deployed and running on Google Cloud Platform in just minutes. From there, you can pick and choose what you want to learn. We'll cover storing structured and binary data, authentication, logging, pub/sub events, deploying and scaling your app, and more. Start building and deploying on Google Cloud Platform with a free trial.
Make a Hello World app
Hello Node.js! Deploy a basic Node.js application by using Google App Engine Managed VMs. Your application can automatically scale to serve millions of requests.
Build the Bookshelf app
Learn how to use Google Cloud Platform services to build a full-featured, scalable application with Node.js. This tutorial demonstrates how to store data, authenticate users, monitor your application, and send messages between applications by using pub/sub events.
Client library
The Google Cloud Client Library for Node.js significantly reduces the boilerplate code you have to write. The library provides high-level API abstractions, so they're easier to understand. It embraces idioms of Node.js, works well with the standard library, and integrates better with your codebase. All this means you spend more time creating code that matters to you.
Install the Google Cloud Client Library or view it on GitHub
$ npm install --save gcloud
See some code examples
var gcloud = require('gcloud');
var dataset;
// From Google Compute Engine:
dataset = gcloud.datastore.dataset({
projectId: 'my-project'
});
// Or from elsewhere:
dataset = gcloud.datastore.dataset({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
dataset.get(dataset.key(['Product', 'Computer']), function(err, entity) {
console.log(err || entity);
});
var fs = require('fs');
var gcloud = require('gcloud');
var storage;
// From Google Compute Engine:
storage = gcloud.storage({
projectId: 'my-project'
});
// Or from elsewhere:
storage = gcloud.storage({
keyFilename: '/path/to/keyfile.json',
projectId: 'my-project'
});
// Create a new bucket.
storage.createBucket('my-new-bucket', function(err, bucket) {});
// Reference an existing bucket.
var bucket = storage.bucket('my-bucket');
// Upload a local file to a new file to be created in your bucket.
fs.createReadStream('/local/file.txt').pipe(bucket.file('file.txt').createWriteStream());
// Download a remote file to a new local file.
bucket.file('photo.jpg').createReadStream().pipe(fs.createWriteStream('/local/photo.jpg'));
var gcloud = require('gcloud');
var pubsub;
// From Google Compute Engine:
pubsub = gcloud.pubsub({
projectId: 'my-project',
});
// Or from elsewhere:
pubsub = gcloud.pubsub({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Create a new topic.
pubsub.createTopic('my-new-topic', function(err, topic) {});
// Reference an existing topic.
var topic = pubsub.topic('my-existing-topic');
// Publish a message to the topic.
topic.publish('New message!', function(err) {});
// Subscribe to the topic.
topic.subscribe('new-subscription', function(err, subscription) {
// Register listeners to start pulling for messages.
function onError(err) {}
function onMessage(message) {}
subscription.on('error', onError);
subscription.on('message', onMessage);
// Remove listeners to stop pulling for messages.
subscription.removeListener('message', onMessage);
subscription.removeListener('error', onError);
});
var gcloud = require('gcloud');
var bigquery;
// From Google Compute Engine:
bigquery = gcloud.bigquery({
projectId: 'my-project'
});
// Or from elsewhere:
bigquery = gcloud.bigquery({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});
// Access an existing dataset.
var schoolsDataset = bigquery.dataset('schools');
// Import data into a dataset.
schoolsDataset.import('/local/file.json', function(err, job) {});
// Get results from a query job.
bigquery.job('job-id').getQueryResults(function(err, rows, nextQuery) {});
// Get the same results as a readable stream.
bigquery.job('job-id')
.getQueryResults()
.pipe(require('through2').obj(function(row, enc, next) {
this.push(row.address + '\n');
next();
}))
.pipe(process.stdout);