Illia (1) [Avatar] Offline
#1
The first code example needs revising.

Looks like gcloud package has been deprecated:
npm WARN deprecated gcloud@0.37.0: gcloud has been renamed to google-cloud. To get new features and bug fixes, you must use the new package.

Also, the first example will not work without setting up the default credentials.

One more thing. I am using gcloud@0.37.0. In this version of the package operation.onComplete is not defined.
Therefore, instead of

operation.onComplete(function(err) {
        console.log('Stopped!');
});


It should be:
operation.on('complete', function(err) {
        console.log('Stopped!');
});




Thanks.
JJ Geewax (8) [Avatar] Offline
#2
Awesome - thanks for the feedback. I'm going to give another pass to Chapter 1 (and a few others) with updates to the install (npm install google-cloud) and code snippets (.on('complete'))
460757 (3) [Avatar] Offline
#3
FWIW, I was going to post similar comments about using npm -g on windows and the step about creating the default credentials.

Also, going back to section 1.6.1 since I am posting this; by default I only had the API section available on my new free project dashboard; I had to go to "Customize" and turn on the Compute Engine section to continue with that project.
rafalgorzkowski (27) [Avatar] Offline
#4
I found the same issue, so I moved to google-cloud library. Here is my code snippet (for Listing 1.9. script.js):

const Compute = require('@google-cloud/compute');

const compute = new Compute({
    projectId: 'my-project-id'
});

function getVmsExample(callback) {
  const options = {
    maxResults: 1
  };
  compute.getVMs(options, (err, vms) => {
    if (err) {
      return callback(err);
    }

    console.log('VMs:', vms);
    callback(null, vms);
  });
}

exports.main = cb => {
  getVmsExample(cb);
};

if (module === require.main) {
  exports.main(console.log);
}