Jun 9, 2012 node · opal · rails · ruby · javascript · roflscale

“Use Node.js FOR SPEED” — @RoflscaleTips

So I obeyed, and wrote the opal NPM package, this way, finally, Rails and opal-rails are no longer necessary. Here’s my first node app:

server = Server.new 3000
server.start do
  [200, {'Content-Type' => 'text/plain'}, ["Hello World!\n"]]

For it I had to write the Server class:

class Server
  def initialize port
    @http = `require('http')`
    @port = port

  def start &block
      this.http.createServer(function(req, res) {
        var rackResponse = (block.call(block._s, req, res));
        res.end(rackResponse[2].join(' '));

Put them in app.opal and then start the server:

$ npm install -g opal      # <<< install the NPM package first!
$ opal-node app

The running app

YAY! now I can roflSCALE all of my RAils apps!!1