I'm facing a challenge with two files - alarm.js
and notifications.js
. In alarm.js
, I need to invoke a method named sendPush
from notifications.js
.
My attempted solution:
I tried exporting the function from notifications.js
:
module.exports.sendPush = function(params){
console.log("sendPush from notifcations.js called");
console.log(params);
}
Then, I imported it in alarm.js
and attempted to use it :
let helperNotif = require('./notifications')
router.post("/", async (req, res) => {
const params = {
param1: 'a',
param2: 'b'
}
helperNotif.sendPush(params)
});
The issue at hand:
Despite my efforts, I keep encountering an error stating that
helperNotif.sendPush is not a function
The main concern:
How can I successfully call the notification.js sendPush
function from my alarm.js
file?
[EDIT] It's worth mentioning that in notifications.js
, there are some router.get
and router.post
functions followed by module.exports = router;
at the end.