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

213
Views
Node js error, "myFunction" is not a function

So I am using the fcm-node package in order to send notifications from the Express api route to the app using a registration token.

The function is:

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
};

I made sure that if outside the function, the notification system is running. Now In the api endpoint:

const sendNotification = require('../sendNotification');

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

I keep on getting the error "sendNotification" is not a function. What is the cause of this?

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

0

try this:

module.exports = sendNotification

and use it like this:

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

0

Expression require('../sendNotification'); is giving you a object (because you exported a object in this file), so extract what you need out.

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!