ES6のimportでFirebase Admin, Cloud Storageを書く
5281 ワード
JavaScript -> TypeScript の変換をしていく中で、なかなか見つからなかったのでメモがてら
import * as admin from 'firebase-admin';
import * as serviceAccount from './serviceAccountKey.json';
import { Storage } from '@google-cloud/storage';
const params = {
type: serviceAccount.type,
projectId: serviceAccount.project_id,
privateKeyId: serviceAccount.private_key_id,
privateKey: serviceAccount.private_key,
clientEmail: serviceAccount.client_email,
clientId: serviceAccount.client_id,
authUri: serviceAccount.auth_uri,
tokenUri: serviceAccount.token_uri,
authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
clientC509CertUrl: serviceAccount.client_x509_cert_url
};
// firebase admin
admin.initializeApp({ credential: admin.credential.cert(params) });
// firestore
const db = admin.firestore();
db.settings({
timestampsInSnapshots: true
});
// cloud storage
const storage = new Storage({
credentials: {
client_email: serviceAccount.client_email,
private_key: serviceAccount.private_key
}
});
以上です
参考
Author And Source
この問題について(ES6のimportでFirebase Admin, Cloud Storageを書く), 我々は、より多くの情報をここで見つけました https://qiita.com/paranishian/items/5589e5d18b076a96b858著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .