該当するフォルダを事前に作成する必要がある
download.js
const admin = require('firebase-admin');
const fs = require('fs');
const serviceAccount = require("path/to/serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "<BUCKET_NAME>.appspot.com"
});
const bucket = admin.storage().bucket();
async function main() {
const files = await bucket.getFiles();
files[0].forEach(async (file) => {
const filePath = `./work/${file.name}`;
if (!fs.existsSync(filePath)) {
console.log(filePath);
await file.download({ destination: filePath });
}
});
}
main().then();
gsutilの方が良さそう