Sinatra e Rails sono entrambi framework Web. Forniscono abstrazioni di sviluppo web comuni, come routing, template, file serving, ecc.
node.js è molto diverso. Al suo nucleo, node.js è una combinazione di V8 e librerie di eventi, insieme a una libreria standard orientata agli eventi. node.js è migliore rispetto a EventMachine per Ruby.
Per esempio, ecco un server HTTP basato su eventi, utilizzando EventMachine:
require 'eventmachine'
require 'evma_httpserver'
class MyHttpServer < EM::Connection
include EM::HttpServer
def post_init
super
no_environment_strings
end
def process_http_request
response = EM::DelegatedHttpResponse.new(self)
response.status = 200
response.content_type 'text/plain'
response.content = 'Hello world'
response.send_response
end
end
EM.run{
EM.start_server '0.0.0.0', 8080, MyHttpServer
}
Ed ecco un esempio node.js:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello world');
}).listen(8000);
Il vantaggio di questo approccio è che il server doesn bloccare su ogni richiesta (possono essere elaborate in parallelo)!
node.js ha il suo intero standard library built around the concept of events che significa che è molto più adatto a qualsiasi problema che sia legato all'I/O. Un buon esempio potrebbe essere un chat application.
Sinatra e Rails sono due framework Web molto raffinati, stabili e popolari. node.js ha alcuni framework web ma nessuno di questi ha la qualità di nessuno di questi al momento.
Fuori dalle scelte, se avessi bisogno di un'applicazione web più stabile, sceglierei Sinatra o Rails. Se avessi bisogno di qualcosa di più altamente scalabile e/o vario, andrei per node.js