firebase-tools:
$ firebase --version
8.4.2
$ node -v
v10.16.3
Platform: macOS
index.js
const admin = require('firebase-admin');
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';
admin.initializeApp();
let db = admin.firestore();
async function test() {
let docRef = db.collection('users').doc('alovelace2');
let setAda = docRef.set({
first: 'Ada',
last: 'Lovelace',
born: 1815
});
}
test()
package.json
{
"name": "firebase-emulator-ui-test",
"version": "1.0.0",
"main": "index.js",
"author": "Chris Hager <[email protected]>",
"license": "MIT",
"dependencies": {
"firebase-admin": "^8.12.1"
}
}
I simply created a new directory, initialise firebase with firebase init and the node project with yarn init, and added firebase-admin (yarn add firebase-admin).
Firebase UI at http://localhost:4000/firestore should show the data.
Firebase UI at http://localhost:4000/firestore shows only an empty root.
Found the answer -- when calling admin.initializeApp() you need to set the correct projectId, then the data will show up.
To add to this, I got the same issue when creating different project environments via firebase use [your environment name]. The local emulator was working, just not showing any data. Once I switched my config settings to the correct environment, all was well and data started showing up in the emulator.
Found the answer -- when calling
admin.initializeApp()you need to set the correctprojectId, then the data will show up.
Embarrassing that this isn't in the documentation more clearly.
@basickarl calling something embarrassing isn't very constructive, also this IS in the documentation:
Link:
https://firebase.google.com/docs/emulator-suite/connect_firestore#admin_sdks
Screenshot:

@samtstern Well that is absolutely delightful for a person who knows _where to find it_. Google documentation together with Microsoft has always been a wall-of-text mess.
My script does set the projectId, and I still have this issue. I am running firebase 8.16.2.
My scripts are reading from and writing to the emulator fine, but if I go into the Emulator UI, there is no data shown. I can only view the collections, documents, subcollections, etc. if I manually create the top-level collection and documents. If I use the Cloud Firestore without the emulator, the same scripts work fine and I can view all the data in the UI without any manual intervention. Please advise.
Most helpful comment
Found the answer -- when calling
admin.initializeApp()you need to set the correctprojectId, then the data will show up.