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

242
Views
Error de nodo js, "myFunction" no es una función

Así que estoy usando el paquete fcm-node para enviar notificaciones desde la ruta Express api a la aplicación usando un token de registro.

La función es:

 const FCM = require('fcm-node'); const serverKey = ... const fcm = new FCM(serverKey); function sendNotification(registrationToken, title, body, dataTitle, dataBody) { const message = { to: registrationToken, notification: { title: title, body: body }, data: { title: dataTitle, body: dataBody } }; fcm.send(message, (err, response) => { if (err) console.log('Error ', err) else console.log('response ', response) }); }; module.exports = { sendNotification };

Me aseguré de que si está fuera de la función, el sistema de notificación se está ejecutando. Ahora en el punto final de API:

 const sendNotification = require('../sendNotification'); router.get('/test', async (req, res, next) => { sendNotification('...', 'hi', 'bye','1', '2'); return res.send(200) };

Sigo recibiendo el error "sendNotification" no es una función. ¿Cuál es la causa de esto?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

prueba esto:

 module.exports = sendNotification

y usarlo así:

 const sendNotification = require('../sendNotification');
about 4 years ago · Juan Pablo Isaza Report

0

Expresión require('../sendNotification'); le está dando un objeto (porque exportó un objeto en este archivo), así que extraiga lo que necesita.

 const { sendNotification } = require('../sendNotification');
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!