When ever I use the command 'firebase serve', the localhost address that is provided to me does not actually work.
The error that I am getting says that some credentials could not be loaded. According to other overflow answers, I am defining functions, admin and initializing the app correctly.
const functions = require('firebase-functions');
// importing the admin
const admin = require('firebase-admin');
// initializing the application in order to use app
admin.initializeApp();
// setting up express
const express = require('express')
const app = express();
app.post('/scream' ,(req, res) =>{
const newScream ={
// second body is a property of the request
body: req.body.body,
userHandle: req.body.userHandle,
createdAt: admin.firestore.Timestamp.fromDate(new Date())
}
admin.firestore().collection('screams').add(newScream)
.then(doc => {
// string literal for response stating successful addition of the newScream object
res.json({message: `doucument${doc.id} created successfully`})
})
.catch((err)=>{
res.status(500).json({error: 'Something went wrong'})
console.log(err)
})
})
exports.api= functions.https.onRequest(app)
I am expecting to run 'firebase serve', get the localhost address, and then use a post method with a json body to test the route in Postman. I am expecting a successful route however credentials do not load so the attempt ends before I can post anything to the database.