title: How to emit event with Socket.io and Node.js?
body: <p>I find it hard to emit an event because I don't know much about creating an event/emitting an event with socket IO.</p>
  
  <p>Here is my problem on CASE "/publish":</p>
  
  <pre><code>var app = http.createServer(function (req, res) {
      if (req.method == "OPTIONS") {
          res.header('Access-Control-Allow-Origin', '*:*');
          res.send(200);
      } else {
  
          var u = url.parse(req.url,true),
              body = '';
  
          req.on('data',function(chunk) {
              body += chunk;
          });
  
          req.on('end',function() {
              if(body) {
                  var data =JSON.parse(body);
                  if(data._app_secret &amp;&amp; data._app_secret == 'nonexistent') {
                      switch(u.pathname) {
                          case '/generateusersecret' :
                              findTokenByUser(req.headers.host+'_'+data.user_id,function(reply) {
                                  if(reply) {
                                      jsonResponse(res,{userSecret : reply});
                                  } else {
                                      generateToken(req.headers.host + '_' + data.user_id,data.user_id,res);
                                  }
                              });
                          break;
                          case '/getusersecret' :
                              findTokenByUser(req.headers.host + '_' + data.user_id,function(reply) {
                                  jsonResponse(res,{userSecret : reply});
                                  console.log(reply);
                              });
                          break;
                          case '/publish':
                              if(data.type == 'notification'){
                                  var newData = {
                                      item_id : data.item_id,
                                      message : data.message,
                                      recipient : data.channel,
                                      itemLink : data.itemLink,
                                      timestamp : data.timestamp,
                                      read : 0
                                  }
                                  notification = JSON.stringify(newData);
                                       // I need to emit my event here
                                       Socket.emit(THE EVENT HERE,notification DATA)
                              }
  
                          break;
                          default: 
                              jsonResponse(res,{error : "Unknown Command: " + u.pathname});
                          break
                      }
                  } else {
                      res.writeHead(403, {'Content-Type': 'text/plain'});
                      res.end('Not authorized');
                  }
              }
          });
      }
  });
  
  app.listen(config.port || 4000, null);
  </code></pre>
  
  <p>Then I need to listen on:</p>
  
  <pre><code>io.sockets.on('connection'function(socket){
     socket.on('THE EVENT HERE',function(NOTIFICATION DATA){
        //I NEED TO EMIT ANOTHER EVENT HERE
     })
  })
  </code></pre>
  
  <p>Is there a possible way for this? I have to do this because I am using PHP's cURL and I can't emit on client side so I need to emit it on server side.</p>