Accessing Google API using Service Account in Node.js was quite helpful for me but it was little bit out of date(due to written based on older api library).
I put my version of snippet which works with latest nodejs client library. Hope it helps
#!/usr/bin/env coffee
googleapis = require('googleapis')
email = SERVICE_ACCOUNT_EMAIL
# see https://developers.google.com/storage/docs/authentication#converting-the-private-key for how to convert .p12 to .pem
keypath = SERVICE_ACCOUNT_PEM
key = null
storage = googleapis.storage('v1')
# see https://developers.google.com/storage/docs/authentication
# for auth url
authClient = new googleapis.auth.JWT(email, keypath, key, ['https://www.googleapis.com/auth/devstorage.read_only'] )
authClient.authorize (err, tokens) ->
if (err)
console.log(err)
return
storage.objects.get {
auth: authClient,
bucket: 'billing-exports',
object: 'bill-2014-09-08.json?alt=media' # add '?alt=media' to download the file itself.
}, (err, file) ->
console.log err, file