Caution: The absence of FIREBASE_CONFIG and GCLOUD_PROJECT environment variables may result in the failure to initialize firebase-admin

I followed a tutorial to set up the Firebase Admin SDK.

https://firebase.google.com/docs/admin/setup

I downloaded a JSON file (service account) from the Firebase console located at:

C:\ct\functions\src\cargo-tender-firebase-adminsdk-8e307-c6b82762d2.json

I added an environment variable:

GOOGLE_APPLICATION_CREDENTIALS=C:\ct\functions\src\cargo-tender-firebase-adminsdk-8e307-c6b82762d2.json

However, upon running the script, a Warning is displayed:

Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail

How can I address this issue and test the code? I intend to send Push notifications in the onCreate event.

The code snippet is as follows:

"use strict";
exports.__esModule = true;
var functions = require("firebase-functions");
var admin = require("firebase-admin");

admin.initializeApp({
    credential: admin.credential.applicationDefault(),
    databaseURL: 'https://cargo-tender.firebaseio.com'
});

exports.sendPushNotification = functions.database
    .ref('/user-chat')
    .onCreate(function (event) {
    var payload = {
        notification: {
            title: 'Title',
            body: 'come check it',
            badge: '0',
            sound: 'default'
        }
    };
    return admin
        .database()
        .ref('fcmToken')
        .once('value')
        .then(function (allToken) {
        if (allToken.val()) {
            var token = Object.keys(allToken.val());
            return admin
                .messaging()
                .sendToDevice(token, payload)
                .then(function (response) {
                    // 
                });
        }
    });
});

Software versions:

PS C:\ct\functions> tsc -v
Version 3.5.2
PS C:\ct\functions> firebase -V
7.0.2
PS C:\ct\functions> node -v
v10.16.0
PS C:\ct\functions> npm -v
6.9.0

Answer №1

After some research, I learned that it's recommended to set up an emulator to test locally. Additionally, I discovered a helpful functions page on the firebase console which allows me to test functions and view the outputs of console.log().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting a string[] to an EventEmitter string[] in Angular 4 with TypeScript: Step-by-step guide

Programming Language: Typescript – written as .ts files Development Framework: Angular 4 I'm currently working on an application that is supposed to add chips (similar to tags in Angular 1) whenever a user types something into the input box and hi ...

Creating a web application using Aframe and NextJs with typescript without the use of tags

I'm still trying to wrap my head around Aframe. I managed to load it, but I'm having trouble using the tags I want, such as and I can't figure out how to load a model with an Entity or make it animate. Something must be off in my approach. ...

generate a dropdown menu within a CSV file using JavaScript

Currently, I am working on exporting a CSV file in Reactjs and facing an issue with creating a dropdown in the generated CSV file. I have attempted using plugins like excel.js, shell.js, as well as csvlink download. <CSVLink data={data}>Download me ...

Attempting to redeclare a previously exported variable will result in an error stating: "Cannot

I'm currently facing an issue with a npm module located in a different directory that I've linked to another project using npm link. Despite successfully compiling the typescript, when I try to import the module and use its function, I encounter ...

Encountering obstacles with Npm when attempting to add dependencies to a loopback (strongloop) web application

Entering the NodeJS world as a newcomer, I successfully created a loopback(strongloop) webapp. However, when attempting to execute the npm install command within the application directory, I encountered the following output on my Ubuntu server 14.04 with t ...

encountering an issue: "trigger new TypeError('JwtStrategy needs a secret or key');"

While attempting to run my web application, I encountered the following error: throw new TypeError('JwtStrategy requires a secret or key'); ^ TypeError: JwtStrategy requires a secret or key at new JwtStrategy (/Users/smitsanghvi/Des ...

What impact does introducing a constraint to a generic type have on the inference process?

Let's take a look at this scenario: function identity<T>(arr: T[]) { return arr } identity(["a", "b"]) In the above code snippet, the generic type T is inferred as string, which seems logical. However, when we introduce a ...

How to prevent redundant object declarations when passing parameters in TypeScript?

Motivation for Using Object Parameters One of the motivations behind using objects as function parameters is to allow the caller to clearly define arguments with specified field names, which can make code reviews easier. Challenge When Using Implements an ...

Issue with narrowing TypeScript arrays often encountered

When working with arrays of strings in my TypeScript code, I restrict the contents to certain letters by using a defined type like ("A" | "B")[] for letters such as A and B. However, when I have a function that takes an arbitrary array ...

Gaining entry to a static member of an exported class in a module

I am facing an issue with my Typescript code snippet. The code is as follows: module MyModule { export class MyClass { static MyStaticMember : string; } } My requirement is to access this code from a separate file after compilation. I tri ...

Create a TypeScript function that can be called and has an extended prototype definition

I am seeking to create a callable function foo() (without using the new operator) that will also include a property foo.bar(). The JavaScript implementation would be as follows: function foo() { // ... } foo.prototype.bar = function bar() { // .. ...

Definition of TypeScript array properties

Having some trouble creating a type for an array with properties. Can't seem to figure out how to add typings to it, wondering if it's even possible. // Scale of font weights const fontWeights: FontWeights = [300, 400, 500]; // Font weight alia ...

The element access has been upgraded to utilize ng-content

I attempted to create a tabs component that could be used similarly to Angular Material Component. However, the solution I came up with was flawed and buggy. In this attempt, I utilized document.getElementsByTagName('app-tab'). This is the temp ...

Getting all parameters from an object in Express - a step-by-step guide

Is there a way to get the entire object without using req.params.users, but instead receive all the data sent from react-native? This is because the URL could be very lengthy like https://example.com/createUser/myname/myrole/myic/myaddress/mybirthday. Idea ...

Testing the NestJS service with a real database comparison

I'm looking to test my Nest service using a real database, rather than just a mock object. While I understand that most unit tests should use mocks, there are times when testing against the actual database is more appropriate. After scouring through ...

Guide on incorporating Paddle into your SvelteKit project

I'm struggling to implement a Paddle Inline Checkout in SvelteKit. Every time I try, I keep encountering the error message Name Paddle not found. It seems like the script is not functioning properly. Console Error: Uncaught (in promise) ReferenceErro ...

Enhancing the default functionality of React.FC within Next.js

Currently, I am working on a tutorial in Nextjs that employs the code snippet below in JavaScript. However, I am planning to transition it to TypeScript. Since I am relatively new to TypeScript, I have attempted various solutions from different sources but ...

Design a model class containing two arrow functions stored in variables with a default value

I am looking to create a model class with two variables (label and key) that store functions. Each function should take data as an input object. If no specific functions are specified, default functions should be used. The default label function will retur ...

Looking for a solution to fix the error when installing npm bower?

user@User:~$ sudo npm install -g bower Greetings, I attempted to install bower using the command above but encountered the following error. npm ERR! Linux 3.19.0-28-generic npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "bower" n ...

What steps do I need to take to create npm packages specifically for react-native development?

Which programming languages are essential for creating npm packages that work on both android and ios platforms in react-native development? Can you suggest any helpful documentation or blogs for developing npm packages that support ...