gcloud-node: the Library for Node.js on Google Cloud Platform

Just a few hours ago Google announced very interesting news about improved support for Node.js on its Cloud platform. In fact, a client library for Node.js has been released by BigG for better integration of Cloud Datastore and Cloud Storage into Node.js applications. According to Google announcement, this is just the first of a set of libraries and new APIs that will be released soon to help developers build applications that take full advantage of Google resources. Very good news indeed, that will help the adoption of the Google Cloud Platform by developers who are interested in deploying their application in the Cloud.

What is Node.js?

Node.js is a very interesting technology originally developed by Ryan Dahl a few years ago. Shortly said, Node.js is a cross-platform runtime environment for server-side and networking applications. Node.js applications are written in JavaScript and can be run within the Node.js runtime on different operating systems with no changes. Given its asynchronous architecture, it is commonly used for real-time applications, and its built-in asynchronous I/O library for file, socket and HTTP communication opened the door to a lot of applications that acts as a server without using a native web server like Apache or Nginx. In fact, Node.js become widely popular as a high-performance server-side platform and quickly become the de-facto standard for server-side JavaScript.

Node.js is not free from accusations of being a bad technology. For example, many developers complain about the single-threaded design of Node.js, that doesn’t take advantage of modern multi-core CPUs. Some others criticize it for not being ready for distributed applications, or for its immaturity, or for the availability of a potentially risky package manager, and even more. No technology is perfect, and Node.js isn’t too, of course. It’s a very interesting framework that found many different areas where it fits perfectly and does a really great job. It comes to no surprise to me that Google saw such a big value in it to write and deliver a dedicated library.

gcloud-node

The new library Google wrote and announced today is targeted at reducing the boilerplate code you need to write when you try to access GCP services. Installation is quite easy, thanks to the availability of the software through the Node.js Package Manager under the name of “gcloud“. Being released under an open source license though, you can expect to find it available in top tier Linux distributions’ archives very soon. In any case, the configuration is quite easy and mostly consists of setting up the authentication. Quite interestingly, this is almost automatic if you deployed gcloud on Google Compute Engine instance that is already prepared to use service accounts: Google just takes care of everything. Otherwise, you need to turn on the APIs you are interested in from your Google Developers Console, adding the necessary credentials (client ID or JSON key) as always.

gcloud currently supports just two services: Cloud Datastore and Cloud Storage. It’s a shame other good stuff in the Google Cloud Platform is not available to gcloud-node yet, but hopefully, this will be fixed very soon. Nevertheless, the effort you need to spend to integrate those services seems quite small indeed. For example, take a look at this snippet of code, an example of integration with Datastore taken from Google’s announcement itself:
var gcloud = require('gcloud');
var dataset = new gcloud.datastore.Dataset({
projectId: 'my-project',
keyFilename: '/path/to/keyfile.json'
});

dataset.get(dataset.key('Product', 123), function(err, entity) {
console.log(err, entity);
});

Quite simple and effective indeed. And the availability of gcloud’s code on GitHub will definitely help it grow faster, thanks to contributions and bugfixes by community members who are interested in it. For more information about gcloud-node, take a look at the extensive documentation Google wrote on gcloud’s website.

Cloud Academy