Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

javascript - 什么是Node.js? [关闭](What is Node.js? [closed])

I don't fully get what Node.js is all about.

(我没有完全了解Node.js的全部内容。)

Maybe it's because I am mainly a web based business application developer.

(也许是因为我主要是一个基于Web的业务应用程序开发人员。)

What is it and what is the use of it?

(它是什么以及它的用途是什么?)

My understanding so far is that:

(到目前为止,我的理解是:)

  1. The programming model is event driven, especially the way it handles I/O .

    (编程模型是事件驱动的,尤其是它处理I / O的方式 。)

  2. It uses JavaScript and the parser is V8 .

    (它使用JavaScript ,解析器是V8 。)

  3. It can be easily used to create concurrent server applications.

    (它可以很容易地用于创建并发服务器应用程序。)

Are my understandings correct?

(我的理解是否正确?)

If yes, then what are the benefits of evented I/O, is it just more for the concurrency stuff?

(如果是,那么即使I / O有什么好处,它对于并发性的东西更多吗?)

Also, is the direction of Node.js to become a framework like, JavaScript based (V8 based) programming model?

(另外,Node.js的方向是成为一个类似于基于JavaScript(V8的)编程模型的框架吗?)

  ask by Jeff translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I use Node.js at work, and find it to be very powerful.

(我在工作中使用Node.js,并发现它非常强大。)

Forced to choose one word to describe Node.js, I'd say "interesting" (which is not a purely positive adjective).

(被迫选择一个词来描述Node.js,我会说“有趣”(这不是一个纯正的形容词)。)

The community is vibrant and growing.

(社区充满活力,不断发展壮大。)

JavaScript, despite its oddities can be a great language to code in. And you will daily rethink your own understanding of "best practice" and the patterns of well-structured code.

(尽管JavaScript很奇怪,但它可以成为一种很好的编码语言。而且你每天都会重新思考自己对“最佳实践”和结构良好的代码模式的理解。)

There's an enormous energy of ideas flowing into Node.js right now, and working in it exposes you to all this thinking - great mental weightlifting.

(现在有很多想法流入Node.js,并且在其中工作会让你接触到所有这些想法 - 伟大的精神举重。)

Node.js in production is definitely possible, but far from the "turn-key" deployment seemingly promised by the documentation.

(生产中的Node.js绝对是可能的,但远不是文档似乎承诺的“交钥匙”部署。)

With Node.js v0.6.x, "cluster" has been integrated into the platform, providing one of the essential building blocks, but my "production.js" script is still ~150 lines of logic to handle stuff like creating the log directory, recycling dead workers, etc. For a "serious" production service, you also need to be prepared to throttle incoming connections and do all the stuff that Apache does for PHP .

(使用Node.js v0.6.x,“cluster”已经集成到平台中,提供了一个基本构建块,但我的“production.js”脚本仍然是?150行逻辑来处理诸如创建日志之类的东西对于“严肃”的生产服务,您还需要准备好限制传入的连接并完成Apache为PHP所做的所有事情。)

To be fair, Ruby on Rails has this exact problem.

(为了公平起见, Ruby on Rails的有这个确切的问题。)

It is solved via two complementary mechanisms: 1) Putting Ruby on Rails/Node.js behind a dedicated webserver (written in C and tested to hell and back) like Nginx (or Apache / Lighttd ).

(它通过两种互补机制解决:1)将Ruby放在Rails / Node.js后面的专用网络服务器(用C语言编写并经过测试到地狱和后面),如Nginx (或Apache / Lighttd )。)

The webserver can efficiently serve static content, access logging, rewrite URLs, terminate SSL , enforce access rules, and manage multiple sub-services.

(Web服务器可以有效地提供静态内容,访问日志记录,重写URL,终止SSL ,实施访问规则以及管理多个子服务。)

For requests that hit the actual node service, the webserver proxies the request through.

(对于访问实际节点服务的请求,Web服务器代理请求。)

2) Using a framework like Unicorn that will manage the worker processes, recycle them periodically, etc. I've yet to find a Node.js serving framework that seems fully baked;

(2)使用像Unicorn这样的框架来管理工作进程,定期回收它们等等。我还没有找到一个看似完全烘焙的Node.js服务框架;)

it may exist, but I haven't found it yet and still use ~150 lines in my hand-rolled "production.js".

(它可能存在,但我还没有找到它,仍然在我的手工卷“production.js”中使用~150行。)

Reading frameworks like Express makes it seem like the standard practice is to just serve everything through one jack-of-all-trades Node.js service ... "app.use(express.static(__dirname + '/public'))".

(像Express这样的阅读框架使得看起来标准的做法就是通过一个全能的Node.js服务来提供所有服务......“app.use(express.static(__ dirname +'/ public'))” 。)

For lower-load services and development, that's probably fine.

(对于负载较低的服务和开发,这可能很好。)

But as soon as you try to put big time load on your service and have it run 24/7, you'll quickly discover the motivations that push big sites to have well baked, hardened C-code like Nginx fronting their site and handling all of the static content requests (...until you set up a CDN , like Amazon CloudFront )).

(但是一旦你试图把大量的时间加载到你的服务上并让它全天候运行,你就会很快发现推动大型网站拥有良好出色的硬化C代码的动机,如Nginx面向他们的网站并处理所有静态内容请求(...直到您设置CDN ,如Amazon CloudFront ))。)

For a somewhat humorous and unabashedly negative take on this, see this guy .

(对于这个有点幽默和毫不掩饰的负面看法,请看这个人 。)

Node.js is also finding more and more non-service uses.

(Node.js也发现越来越多的非服务用途。)

Even if you are using something else to serve web content, you might still use Node.js as a build tool, using npm modules to organize your code, Browserify to stitch it into a single asset, and uglify-js to minify it for deployment.

(即使您使用其他东西来提供Web内容,您仍然可以使用Node.js作为构建工具,使用npm模块来组织代码,使用Browserify将其拼接成单个资源,并使用uglify-js将其缩小以进行部署。)

For dealing with the web, JavaScript is a perfect impedance match and frequently that makes it the easiest route of attack.

(对于处理Web,JavaScript是一种完美的阻抗匹配,并且经常使其成为最简单的攻击途径。)

For example, if you want to grovel through a bunch of JSON response payloads, you should use my underscore-CLI module, the utility-belt of structured data.

(例如,如果要浏览一堆JSON响应有效负载,则应使用我的underscore-CLI模块,即结构化数据的实用程序。)

Pros / Cons:(优点缺点:)

  • Pro: For a server guy, writing JavaScript on the backend has been a "gateway drug" to learning modern UI patterns.

    (Pro:对于服务器人来说,在后端编写JavaScript一直是学习现代UI模式的“门户药物”。)

    I no longer dread writing client code.

    (我不再害怕编写客户端代码。)

  • Pro: Tends to encourage proper error checking (err is returned by virtually all callbacks, nagging the programmer to handle it; also, async.js and other libraries handle the "fail if any of these subtasks fails" paradigm much better than typical synchronous code)

    (Pro:倾向于鼓励正确的错误检查(几乎所有的回调都会返回错误,唠叨程序员来处理它;同样,async.js和其他库处理“如果任何这些子任务失败则失败”范式比典型的同步代码好得多))

  • Pro: Some interesting and normally hard tasks become trivial - like getting status on tasks in flight, communicating between workers, or sharing cache state

    (专业:一些有趣且通常很难的任务变得微不足道 - 比如获取飞行中的任务状态,工作人员之间的通信或共享缓存状态)

  • Pro: Huge community and tons of great libraries based on a solid package manager (npm)

    (专业:基于坚实的包管理器(npm)的庞大社区和大量优秀的图书馆)

  • Con: JavaScript has no standard library.

    (Con:JavaScript没有标准库。)

    You get so used to importing functionality that it feels weird when you use JSON.parse or some other build in method that doesn't require adding an npm module.

    (当你使用JSON.parse或其他一些不需要添加npm模块的方法时,你已经习惯了导入功能,感觉很奇怪。)

    This means that there are five versions of everything.

    (这意味着一切都有五个版本。)

    Even the modules included in the Node.js "core" have five more variants should you be unhappy with the default implementation.

    (如果您对默认实现不满意,即使Node.js“核心”中包含的模块还有五个变体。)

    This leads to rapid evolution, but also some level of confusion.

    (这导致快速进化,但也有一定程度的混乱。)

Versus a simple one-process-per-request model ( LAMP ):(与每个请求的简单单进程模型( LAMP ):)

  • Pro: Scalable to thousands of active connections.<

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...