0

I try to sign a response message using Google Cloud KMS.

But immediately get an error.

index.js:

// Imports the Google Cloud client library
const kms = require('@google-cloud/kms');

exports.helloKms = (req, res) => {
  let message = req.query.message || req.body.message || 'Hello World!';
  res.status(200).send(message);
};

package.json:

{
  "@google-cloud/kms": "^1.5.3",
  "name": "sample-http",
  "version": "0.0.1"
}

log:

2019-12-01T05:26:37.534Z kms-demo Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module '@google-cloud/kms'
....
2019-12-01T05:26:37.599Z Cloud Functions UpdateFunction us-central1:kms-demo boristep@googlemail.com INVALID_ARGUMENT E  Cloud Functions UpdateFunction us-central1:kms-demo boristep@googlemail.com

Any idea?

BT3
  • 433
  • 6
  • 21

1 Answers1

1

It doesn't look like you actually installed the module properly. If you just edited package.json the way you illustrated, that's not going to work. You should npm install @google-cloud/kms to make sure package.json get installed properly. It will appear in a block called "depenedencies" in your package.json, and new files will appear in node_modules.

You might want to take some time to learn about how npm works for package management.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • I'm saying about cloud function. It is not a nodejs application – BT3 Dec 01 '19 at 07:00
  • 1
    Cloud Functions actually deploys node applications, if that's the runtime you choose. If you're deploying JavaScript, you are deploying it to a node container. The way that dependencies are installed is not any different. – Doug Stevenson Dec 01 '19 at 07:04