Is this a problem with npm or JavaScript?

Hi everyone, I'm trying to figure out if this issue is related to JavaScript or npm. If there's a problem with my JS code, could someone please help me identify it?

PLEASE NOTE I used some code to get the current uid from Firebase. I'm not very experienced in JavaScript programming.

Here's the full code:

let functions = require('firebase-functions');

let admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);
var uid = event.params.uid;
exports.announceProduct = functions.database
 .ref('users/{uid}/notifications')
.onCreate(event => {
   let note = event.data.val();
  sendNotification(note);
  });

function sendNotification(note) {
 let title = note.title;
 let action = note.action;
 let user = note.user;

 let payload = {
notification: {
  title: 'user',
  body: 'action',
  sound: 'default'
}
 };
}

Error output in console:

Error Screenshot

Thank you so much!!

Answer №1

There seems to be a mismatch with opening and closing braces in this code snippet. Add three }'s at the end of the code block. Additionally, there are missing commas for the properties of the payload object. The arrow function syntax is incorrect for the event parameter in the onCreate method. While methods can accept functions as parameters, attempting to declare a function as a parameter is not allowed.

EDIT: Try implementing the following code:

let functions = require('firebase-functions');

let admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);
var uid = event.params.uid;
exports.announceProduct = functions.database
  .ref('users/{uid}/notifications')
  .onCreate(event => {
    let note = event.data.val();
    sendNotification(note);
  });

function sendNotification(note) {
  let title = note.title;
  let action = note.action;
  let user = note.user;

  let payload = {
    notification: {
      title: 'user',
      body: 'action',
      sound: 'default'
    }
  };
}

EDIT: To address your modified question, it appears that you are using the variable event in var uid = event.params.uid without defining it elsewhere.

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

Cease all operations that rely on the npm start command

Running multiple npm tasks in parallel is a useful practice that can be done by separating them with & instead of &&. In my package.json file, it would look something like this: "start": "npm run watch-blog & npm run watch-data & npm run server", Each su ...

The function 'downloadFunc' is not recognized as a valid function within the context of ReactJS custom hooks

Here is a unique custom hook that triggers when the user presses a button, calling an endpoint to download files as a .zip: import { useQuery } from 'react-query'; import { basePath } from '../../config/basePath'; async function downlo ...

Utilizing ng-repeat to loop through a div element that consists of various nested tags

I need to display multiple tabs, with each tab having a table where the values are populated from a database. The number of tabs is dynamic and fetched from another page of the application. All tables have the same structure but different values. How can I ...

Choose particular content enclosed by two strings (across multiple lines)

Looking to use regex to extract specific text between two strings. For example: foo I have four toys bar //single line foo //multiline I have four toys bar foo I have three pets bar foo I have three pets bar How can I extract the text between & ...

Tips for Customizing the Appearance of Material UI Select Popups

My React select component is functioning properly, but I am struggling to apply different background colors and fonts to the select options. https://i.stack.imgur.com/kAJDe.png Select Code <TextField fullWidth select size="small" nam ...

Can you explain how the tagging feature works in the comment section of platforms like Facebook or Azure, where users can mention others by using the '@' symbol?

I am currently working on creating a comment box application similar to Facebook using the MERN stack. While adding simple comments is not difficult, I am curious about how the tagging mechanism works when mentioning a user with an '@' symbol. Sh ...

Surprising Jade Block Error

NOTE: This question is similar to this one, but it's a different issue. I'm working on an expressjs node website, but I keep encountering the following error: src\dynamic\views\index.jade:

_includes/navbars/topNav.jade file ...

Pass back result from function using callback

What is the reason behind router.get('/eventTest/:id', function (req, res) { var event = Event.getEventById(req.params.id, function (err, rows) { if(err) { return err; } else { return rows; } }); res.json(event); } ...

creating sleek animations with Pixi.js for circular shapes

Is it possible to create smooth animations on circles or sprites similar to D3.js hits in Leaflet? https://drive.google.com/file/d/10d5L_zR-MyQf1H9CLDg1wKcvnPQd5mvW/view?usp=sharing While D3 works well with circles, the browser freezes. I am new to Pixi. ...

What is the best way to display the value of a new object's property in Angular?

I am currently developing a list application that allows users to create new lists by entering a name and clicking a button. Once the list is created, users can add and remove items from the list. However, I have encountered an issue where the name of the ...

Secure authentication across multiple domains using Node.js, Passport, and Backbone framework

Currently, I am working with Node.js utilizing an express server and the passport package for authentication. The client is located on a different domain but on the same server and is built using Backbone.js. I have successfully created a session upon logi ...

Incorporate personalized feedback into a datatable with server-side processing

Trying to implement server-side processing for a datatable loaded from an AJAX response using this specific example The server response being received is as follows: {"msg":null,"code":null,"status":null,"result":[{"aNumber":"3224193861","bNumber":"32159 ...

"Enhance your website with captivating Javascript hover effects for

Can anyone assist me with incorporating the navigation hover effect seen on this website into my HTML/CSS project? The example site is built using a WordPress theme, but I am looking to apply that green effect to my own webpage and have the ability to cust ...

The PDFKIT feature ensures that any overflowing data in a row is automatically moved to a new page

A function in my code generates a row of data based on an array. It works perfectly fine for the first page, but as soon as the data overflows somewhere around doc.text("example",70,560), it jumps to the next page. The issue arises when the Y coo ...

Autofill Text Input with React Material-UI

For my current project, I am utilizing Material UI and React. Each TextField in the project has a button next to it, and when the button is clicked, I want it to retrieve the value of its corresponding TextField and set that value as the input for another ...

Best practices for incorporating and leveraging node packages with Laravel Mix

As I embark on my Laravel (v 8.x) Mix project, I am encountering challenges when it comes to incorporating JavaScript from node modules. To kick things off, here is a snippet from my webpack.mix.js: mix.js('node_modules/mxgraph/javascript/mxClient.mi ...

Is it possible to change between universal and spa mode based on the query string?

Currently, I am working on a Nuxt.js application set to universal mode and deployed as a static website using nuxt generate. The app is pulling data from a GraphQL API linked to a CMS, and everything is functioning properly. Whenever content is updated in ...

The onchange event does not seem to be functioning as expected in a dropdown menu that was dynamically added from a separate

Is there a way to display a list of tables from a database in a dropdown menu and allow users to select a table name? When a user selects a table name, I would like to show all the data associated with that table. The HTML file structure is as follows: & ...

Error: Authentication Error - Headers have already been sent to the client and cannot be modified

I am currently working on handling authentication errors for my website. However, when I submit incorrect data, I encounter the following error: node:internal/errors:478 ErrorCaptureStackTrace(err); ^ Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers aft ...

Prevent onClick event in jQuery and extract parameters from a function call

We've been tasked with implementing a temporary solution to some code, so it might seem a bit silly at first. But please bear with us. The goal is to block the onclick method of an anchor tag, extract the parameters from the function call, and then u ...