title: Primus with Express
body: <p>I want to use <a href="https://github.com/primus/primus#how-do-i-use-primus-with-express-3" rel="nofollow">Primus</a> with Express. Primus as abstraction layer to websockets. I used the Primus examples works fine - I used a basic Express examples - works fine. But somehow I can get them working together.</p>
  
  <p>index.html (just the standard primus example html) &amp; primus.js are in folder ./public</p>
  
  <p>Here is what I'm doing.</p>
  
  <pre><code>var express = require('express');
  var Primus = require('primus');
  var http = require('http');
  var path = require('path');
  var app = express();
  
  var server = require('http').createServer(app)
  , primus = new Primus(server, { transformer: 'engine.io' });
  
  
  app.set('port', process.env.PORT || 3000);
  app.use(express.logger('dev'));
  app.use(express.json());       // to support JSON-encoded bodies
  app.use(express.urlencoded()); // to support URL-encoded bodies
  app.use(express.methodOverride());
  
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
  
  
  // development only
  if ('development' == app.get('env')) {
    app.use(express.errorHandler());
  }
  
  primus.on('connection', function connection(spark) {
      console.log('new connection');
      spark.write({ Welcome: 'Hello!' });
  });
  
  primus.save(__dirname +'/public/primus.js');
  
  /* the normal express start
  http.createServer(app).listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
  });
  */
  
  server.listen(app.get('port'), function(){
      console.log('Express server listening on port ' + app.get('port'));
  });
  </code></pre>
  
  <p>Output when accessing </p>
  
  <pre><code>http://localhost:3000/index.html
  
  
  Express server listening on port 3000
  GET /index.html 200 73ms - 5.22kb
  </code></pre>
  
  <p>index.html served correctly. but no request for primus.js shows up. And index.html shows 400 error on get primus.js</p>
  
  <p>When I disable the primus part in the code above and use the normal express start I get the following output:</p>
  
  <pre><code>Express server listening on port 3000
  GET /index.html 200 79ms - 5.22kb
  GET /primus.js 200 69ms - 96.54kb
  </code></pre>
  
  <p>So all served correctly. Prmius works on client but of course nobody at server side answering as I had primus disabled.</p>
  
  <p>Any idea what's wrong? </p>