I have gone through, Nodejs-GCP-Compute-Github doc and used the sample code to create a new VM and list existing VM using NodeJS and Npm module.

Now I want to connect to my existing VM and run a small bash script to invoke a few commands mostly git clone or curl to run files in VM.

I couldn't find a method in @google-cloud/compute to connect to the exisitng VMs and do some stuff.

Do we have any such method?

Is it possible to do this in some other way using Nodejs?

1 Answers

Gelidus On Best Solutions

There are two different methods coming to my mind:

  1. You could add your public key to the instance, and then connect to it via ssh using a node ssh library (https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys)

  2. Set a startup script for the instance when you are creating it. This can be done by setting the second parameter (config) of createVM to something like:

  os: 'ubunntu',
  metadata: {
    'startup-script': 'your commands'