how to refer to a keyfile in .env config
// put the path in the options you pass to the service constructor like BigQuery or Storage
// as in:
const gcs = new Storage({
projectId: process.env.projectId,
keyFilename: `path-to-keyfile.json'
});
// more complete example
const { Storage } = require('@google-cloud/storage');
const gcs = new Storage({
projectId: process.env.projectId,
keyFilename: `${path.join(
__dirname,
'../../../config/creator-test-12345-d3ff016c07a0.json'
)}`,
});
const gcsBucket = gcs.bucket(bucketId, {
userProject: projectId,
});
await gcsBucket
.upload(sourceFilePath, {
destination: targetFileName,
})
.catch((err) => {
console.error(err);
});