title: Execute module after POST request
body: <p>I'm trying to integrate sending real-time information via sockets (using <strong>socket.io</strong>), and sending push notifications using the <strong>OneSignal</strong> platform.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <h3>user.js</h3>
  
  <pre><code>  var express = require('express');
  var router = express.Router();
  var misocket = require('../routes/misocket');
  var notificacion = require('../routes/notificacion');
  
  /*
  
  run module when start server run, i don't want it
  
  notificacion();
  
  */ 
  
  /* GET users listing. sendnote*/
  router.post('/sendasig', function(req, res, next) { 
  
  
      console.log(misocket);//registrednote
      misocket.emit("registrar",req.body);  
    //run here, after the send data across post request
    notificacion();
      console.log(req.body);
  
    res.status(200).json({
        message  : "send message"
    }); 
  
  });
  
  module.exports = router;
  </code></pre>
  
  <h3>notificacion.js</h3>
  
  <pre><code> 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);
          }); 
  
  }; 
  </code></pre>
  
  <h3>index.js</h3>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express' });
  });
  
  module.exports = router;
  </code></pre>
  
  <h3>misocket.js</h3>
  
  <pre><code>var i = 0;
  var ioapp;
  
  exports.connection= function(io){
  
      ioapp = io;
  
      io.on('connect',function(s){
          console.log("Conectado");    
      });
  
  };
  
  exports.io = ioapp;
  </code></pre>