I am getting the following error when trying to connect with a Google Cloud Storage Bucket in a nodejs app based in the Google App Engine.
ApiError: Required parameter: project
at Util.parseHttpRespBody (/workspace/node_modules/@google-cloud/common/build/src/util.js:208:38) at Util.handleResp (/workspace/node_modules/@google-cloud/common/build/src/util.js:149:117)
The code to connect in the server.js file is pretty straightforward:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
storage.getBuckets().then(y => console.log(y));
Both the deployed app and storage bucket are part of the same project.
I have also created a service account for the storage bucket, which has API Keys Admin and Storage Admin roles, and API keys have been generated.
Any help would be much appreciated!
Here is the updated code (with my project id edited):
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
projectId: 'r@@@@@@t-t@@@h-3####9'
});
storage.getBuckets().then(y => console.log(y));
"dependencies": {
"@google-cloud/storage": "^5.15.3",
"body-parser": "^1.19.0",
"dotenv": "^10.0.0",
"ejs": "^3.1.6",
"express": "^4.17.1",
"multer": "^1.4.3",
"pg": "^8.7.1",
"pg-hstore": "^2.3.4",
"sequelize": "^6.6.5",
"sequelize-cli": "^6.2.0"
},
"devDependencies": {
"@types/node": "^14.6.2",
"nodemon": "^2.0.14"
}
Create the client and specify the Project ID (not the project name):
const storage = new Storage({
projectId: 'your-project-id'
});
If you want to specify the service account that you mentioned:
const storage = new Storage({
projectId: 'your-project-id',
keyFilename: '/path/to/service-account-key.json'
});
Documentation: