• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

168
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 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

prueba esto:

 module.exports = sendNotification

y usarlo así:

 const sendNotification = require('../sendNotification');
about 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error