I am trying to integrate sending real-time information through sockets (using socket.io ) and sending push notifications using the OneSignal platform.
It happens that if I put everything in the same module, I donβt know why the method of sending a notification does not work after sending information or before sending information.
If I run the npm start command, the error does not appear, but the notification comes as soon as the local or remote server is running, and so I do not want this to happen.
user.js
var express = require('express'); var router = express.Router(); var misocket = require('../routes/misocket'); var notificacion = require('../routes/notificacion'); router.post('/sendasig', function(req, res, next) { console.log(misocket);
notificacion.js
module.exports = function(){ var OnesignalNotificationApi = require('onesignal-notification'); var api = new OnesignalNotificationApi('N2FkY2ZkZWQtMGQ2MS00ZTUwLTlkM2QtODA2NmE0YjBiMzQ3', 'c4b92cce-4d59-4550-a4be-20939370e39c'); var message = { it: 'Some message', en: 'Some message', es: 'Nueva Calificacion' }; api.sendToAll(message, null, function(err, res){ console.log(err); console.log(res); }); };
index.js
var express = require('express'); var router = express.Router(); router.get('/', function(req, res, next) { res.render('index', { title: 'Express' }); }); module.exports = router;
misocket.js
var i = 0; var ioapp; exports.connection= function(io){ ioapp = io; io.on('connect',function(s){ console.log("Conectado"); }); }; exports.io = ioapp;