title: Node.JS + WebSockets + Express: Download File
body: <p>Ok, so, yeah. I have the following <code>server.js</code> file with a web server + WebSocket implemented and, I was wondering, could I send file content through my WebSocket, and then using Express, create and send a download?</p>
  
  <p><b>Server.js:</b></p>
  
  <pre><code>var express = require('express');
  var app = express();
  var WebSocketServer = require('ws').Server;
  var server = app.listen(80);
  var wss = new WebSocketServer({ port: 8080 });
  
  app.use('/stick', express.static(__dirname + '/stick'));
  
  wss.on('connection', function(ws) {
    console.log('websocket... on!');
  });
  </code></pre>
  
  <p>I was thinking maybe doing something like:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var WebSocketServer = require('ws').Server;
  var server = app.listen(80);
  var wss = new WebSocketServer({ port: 8080 });
  
  app.use('/stick', express.static(__dirname + '/stick'));
  
  wss.on('connection', function(ws) {
    ws.on('download', function(data) {
      server.createRequest('foobar'); // I don't know if this even exists!
      //OR
      server.writeHeader(200, "foobar");
    });
    console.log('websocket... on!');
  });
  </code></pre>
  
  <p>I know with PHP I could just set the headers and echo the content, can I do the same thing here?</p>