Skip to content
This repository
tree: ed02d429b0
Fetching contributors…

Cannot retrieve contributors at this time

file 73 lines (45 sloc) 2.685 kb


Node apps running in any rack server as a endpoint, and potentially a middleware layer.

Leverage authentication, authorization and more in front of your node apps, letting node be used for high concurrency portions of your app.

Reach a node app as an RPC directly from your Rails models (coming soon)


  • Ruby 1.8.7 or 1.9.2 work fine

  • Node.js

brew install node (or equivalent for your environment)


sudo gem install whack-a-node


In Rails 3's routes.rb:

match “/proxy” =>“/”)

This will attempt to reach a node server on localhost at port 8810. The response will be proxied by Rack.

match “/redirect” =>“/”,“”, 2306)

This will redirect to a node server at on port 2306. In some cases, this can result in faster performance, as you don't have to have a Rack instance sitting around for the whole request.

Generally speaking, using the proxy over a Rails controller ends up being about 8-10 times faster. While still much slower than Node directly, this can still yield benefit.


Node server code


var http = require('http'); http.createServer(function (req, res) {

		res.writeHead(200, {'Content-Type': 'text/plain'});
		res.end('Hello World\n');

}).listen(8810, “”); console.log('Server running at');

Start the node server by running node server.js

Rails server

Create a new Rails app. Add the following to routes.rb

match “/proxy” =>“/”) – WhackANode defaults to localhost port 8810, so this will work with above server Add Whack-A-Node to your Gemfile:

gem 'whack-a-node'

Start your Rails app. Hit localhost:3000/proxy. You should see 'Hello World' generated by Node.js

Contributing to whack-a-node

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright © 2011 Niels Meersschaert & Matthew Jording. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.