Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Async/Await don't work in Google cloud functions

I work with google cloud functions and cloud messaging on Firebase. However, when I try to use Async/Await functions, I have an error: error Parsing error: Unexpected token => I work with Node.js v16.

Here is my code:

const functions = require("firebase-functions");
// const mess = require("firebase/messaging");
const admin = require("firebase-admin");

exports.sendListenerPushNotificationProductUpdate = functions.database
    .ref("Products/{product}/type/")
    .onUpdate(async (snapshot, context) => {

      ...

      const tokensSnapshot = await Promise.resolve(getDeviceTokensPromise);
      console.log("TOKEN: " + JSON.stringify(tokensSnapshot));
      // Check if there are any device tokens.
      if (!tokensSnapshot.hasChildren()) {
        return functions.logger.log(
            "There are no notification tokens to send to."
        );
      }
      
       ...

      // Listing all tokens as an array.
      const tokens = Object.keys(tokensSnapshot.val());
      // Send notifications to all tokens.
      const response = await admin.messaging().sendToDevice(tokens, payload);
      // For each message check if there was an error.
      const tokensToRemove = [];
      return Promise.all(tokensToRemove);
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Does getDeviceTokensPromise return a Promise? If so, that line should just be

const tokensSnapshot = await getDeviceTokensPromise()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!