I'm trying to create a google bucket if it does not exist with the following logic:
async function createBucket(id){
const bucket = storage.bucket("bucket-" + id);
const exists = await bucket.exists();
if (!exists) {
console.log("creating bucket>>" + "bucket-" + id);
try {
await bucket.create();
} catch (e) {
console.error("error in creating bucket>>>", e);
}
} else {
console.log("it already exists >>" + exists);
}
}
strangely, I'm seeing it already exists >> false, when I should only see either it already exists >> true or creating bucket>>bucket-123. Any help with resolving this would be much appreciated. Thank you!
storageis initialised? Why not use promise bucket.exits.then(...storage.bucket("bucket-" + id);an asynchronous call too? What happens if you writeawait storage.bucket("bucket-" + id);?