When connect firebase to node project it show db is not defined.
Progress.js
const Progress = require("../models/progress");
//add new Progress
exports.addProgress = async (req, res) => {
//constant variables for the attributes
const {name, description, type, date,imgUrl} = req.body;
//object
const newProgress= new Progress({
//initializing properties
name,
description,
type,
date,
imgUrl
})
//saving the object to the db
newProgress.save().then(() => {
res.status(200).json({ status: "New Progress Added" });
}).catch((error) => {
res.status(500).json({message:"Fail to Progress Item",error:error.message})
})
}
I think you missed to initialize DB, Try This -
const firestore = require("firebase-admin");
const db = firestore.firestore();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.