Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could someone give me an example of node.js application

I'm trying to understand the differences between some of the newer web programming frameworks that now exists, namely Node.js, Rails, and Sinatra.

Could someone give me an example of applications that would work best on each of the frameworks?

That is to say, what is an application that would be best suited for Node.js as opposed to Rails or Sinatra and what is an application that is best suited for Rails as opposed to Node.js and Sinatra etc.....

like image 801
TheDelChop Avatar asked Jun 04 '10 12:06

TheDelChop


People also ask

What is node js used for example?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.

Which application uses node JS?

Here are the companies using Node. js: Netflix, NASA, Trello, PayPal, LinkedIn, Walmart, Uber, Twitter, Yahoo, eBay, GoDaddy, and got much better results.

Do people still use node JS?

Node. js development has become very popular over the last four years and continues to stand the competition in 2022 making startups worldwide choose it over other available options.


1 Answers

Sinatra and Rails are both web frameworks. They provide common web development abstractions, such as routing, templating, file serving, etc.

node.js is very different. At it's core, node.js is a combination of V8 and event libraries, along with an event-oriented standard library. node.js is better compared to EventMachine for Ruby.

For example, here's an event-based HTTP server, using 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
}

And here's a node.js example:

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello world');
}).listen(8000);

The benefit of this approach is that the server doesn't block on each request (they can be processed in parallel)!

node.js has its whole standard library built around the concept of events meaning that it's much better suited to any problem that is I/O bound. A good example would be a chat application.

Sinatra and Rails are both very refined, stable and popular web frameworks. node.js has a few web frameworks but none of them are at the quality of either of those at the moment.

Out of the choices, if I needed a more stable web application, I'd go for either Sinatra or Rails. If I needed something more highly scalable and/or diverse, I'd go for node.js

like image 198
Brian McKenna Avatar answered Oct 06 '22 00:10

Brian McKenna