You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
587 B

7 years ago
  1. var fs = require('fs'),
  2. union = require('union');
  3. var server = union.createServer({
  4. before: [
  5. function (req, res) {
  6. fs.readFile(__dirname + '/index.html',
  7. function (err, data) {
  8. if (err) {
  9. res.writeHead(500);
  10. return res.end('Error loading index.html');
  11. }
  12. res.writeHead(200);
  13. res.end(data);
  14. });
  15. }
  16. ]
  17. });
  18. server.listen(9090);
  19. var io = require('socket.io').listen(server);
  20. io.sockets.on('connection', function (socket) {
  21. socket.emit('news', {hello: 'world'});
  22. socket.on('my other event', function (data) {
  23. console.log(data);
  24. });
  25. });