LoginSignup
3
6

More than 3 years have passed since last update.

Firebase Cloud FirestoreをNode.jsから利用するスニペット

Posted at

毎回忘れるのでメモです。

テストモード利用でチェック。

$ npm i firebase
app.js
'use strict';

const firebase = require("firebase/app");
require("firebase/firestore");

//この辺をFirebaseの管理画面からコピペ
const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: ""
};

const firebaseApp = firebase.initializeApp(firebaseConfig);

const db = firebaseApp.firestore();
db.collection('collectionName').get() //コレクション名を各々のモノに
 .then((snapshot) => {
  snapshot.forEach((doc) => console.log(doc.data()));
 })
 .catch((err) => console.log('Error getting documents', err));
$ node app.js
3
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6