Sunday 11 June 2017

Run one module after another is run

I'm trying to integrate sending real-time information via sockets (using socket.io), and sending push notifications using the OneSignal platform.

It happens that if I put everything in the same module, I do not know why the method to send the notification is not executed after the information is sent, or before sending the information.

If I run the command npm start no error appears but the notification arrives as soon as the local or remote server is running, and this way I do not want it to happen.

user.js

var express = require('express');
var router = express.Router();
var misocket = require('../routes/misocket');


/* GET users listing. sendnote*/
router.post('/sendasig', function(req, res, next) {

    console.log(misocket);//registrednote

    misocket.emit("registrar",req.body);

    console.log(req.body);

  res.status(200).json({
                    message  : "send message"
                }); 

});

module.exports = router;

notificacion.js

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



via Pedro Miguel Pimienta Morales

No comments:

Post a Comment