本文介绍了有人能给我一个 node.js 应用程序的例子吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解现有的一些较新的 Web 编程框架(即 Node.js、Rails 和 Sinatra)之间的差异.

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?

也就是说,相对于 Rails 或 Sinatra 而言,最适合 Node.js 的应用程序是什么,相对于 Node.js 和 Sinatra 等,最适合 Rails 的应用程序是什么.....

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.....

推荐答案

Sinatra 和 Rails 都是 Web 框架.它们提供常见的 Web 开发抽象,例如路由、模板、文件服务等.

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

node.js 非常不同.node.js 的核心是 V8 和事件库的组合,以及一个面向事件的标准库.与用于 Ruby 的 EventMachine 相比,node.js 更好.

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.

例如,这是一个基于事件的 HTTP 服务器,使用 EventMachine:

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
}

这是一个 node.js 示例:

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 有其完整的 围绕事件概念构建的标准库,这意味着它更适合任何受 I/O 限制的问题.聊天应用程序就是一个很好的例子.

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 和 Rails 都是非常精致、稳定和流行的 Web 框架.node.js 有一些 Web 框架,但目前它们的质量都不如其中任何一个.

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.

在众多选择中,如果我需要更稳定的 Web 应用程序,我会选择 Sinatra 或 Rails.如果我需要更高可扩展性和/或多样化的东西,我会选择 node.js

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

这篇关于有人能给我一个 node.js 应用程序的例子吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 11:11