How to upload data to Firebase Firestore Cloud Database

  • Step 1: Prepare your data in JSON format. You may use excel worksheet to prepare your basic data like this —
  • Step 2: Download service key from your Firebase project. Open your Firebase project > click on settings icon > select “Users and permissions”
  • Step 3: Setup a node.js project to upload your JSON data file to Firestore database. Create a project folder at your preferred location. Open terminal or command prompt and navigate inside that folder and run command npm init
npm install firebase-admin
const admin = require('./node_modules/firebase-admin');const serviceAccount = require("./serviceAccountKey.json");const data = require("./data.json");const collectionKey = "entities"; //name of the collectionadmin.initializeApp({  credential: admin.credential.cert(serviceAccount),  databaseURL: ""});const firestore = admin.firestore();const settings = {timestampsInSnapshots: true};firestore.settings(settings);if (data && (typeof data === "object")) {Object.keys(data).forEach(docKey => { firestore.collection(collectionKey).doc(docKey).set(data[docKey]).then((res) => {    console.log("Document " + docKey + " successfully written!");}).catch((error) => {   console.error("Error writing document: ", error);});});}
code snippet
auto generated document keys
  • Step 4: Execute your program. In terminal go one level up from your project folder , and run below command to execute your upload program —
node <Your_Project_Folder_Name>
“entities” collection uploaded with all data in Firestore database




a passionate coder …

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

JavaScript Array fundamentals for newbies

A Solid Webpack Config and the Knowledge Behind It

Storage API in Javascript

Deploying React App to Google App Engine

Build a Location-based Chatroom with Firebase and Vue.js

Axure Tutorial: Introducing Axure RP Flow Diagram

How to use Angular route resolvers with NgRx store

Exploring Recharts: Pulsating circle using ReferenceDot

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


a passionate coder …

More from Medium

Learnings in the journey towards Node.js from iOS developer — Part 1

The Preferred Backend Frameworks for App Developers

Tips To Hiring A Node.js Developer Guide

Collaborative Drawing App: Canvas & Palette Setup