Node.js的用途-旨在为之提供坡度的障碍是什么? [英] Usages of Node.js - What obstacles is it aiming to provide a ramp for?

查看:86
本文介绍了Node.js的用途-旨在为之提供坡度的障碍是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力弄清Node适合的位置.这是一个利基市场,可以这么说……Node旨在为之提供坡度的障碍是什么?

我已经阅读了示例,并观看了一些演示视频.一切看起来都很圆滑.创建一个简单的TCP/IP聊天服务器;使用Node作为数据库服务器的基于JSON的前端...但是它适合哪里?我的意思是,除了最后一个示例以外,Node与该做什么?

我想我要问的是:您将Node用作什么?为什么呢?

解决方案

说服老板

使用节点的原因列表:

  • 速度. V8速度很快.比python更快,比php更快.
  • 事件IO. IO正确完成.不用搞乱线程,一切都很好且轻松地工作.
  • 低级Web服务器.可以很好地控制动态语言中的抽象.
  • JavaScript.一种很棒的语言,具有许多开发人员在编写异步代码方面的经验.开发速度很快,维护也很方便,因为一切都可以用一种语言(客户端,服务器端,数据库访问)完成.

可与node.js一起使用的库和工具:

  • express.js :MVC Web框架.非常轻巧.给您路由和视图.在connect.js之上构建.开箱即用,可灵活控制视图和路由,并支持多个CSS和模板引擎.与node.js本身一样,它非常简单,可以为您的Web服务器提供精细的控制.我个人在权利的控制和抽象之间找到了平衡.
  • socket.io :实际的Websocket抽象.内置了许多优雅的降级支持,因此没有websocket的浏览器使用彗星技术或Flash Bridge.允许您轻松,轻松,实时地在客户端和服务器之间进行通话.
  • now.js :建立在socket.io之上,并为您提供了跨客户端和服务器的同步名称空间.允许您从客户端轻松调用服务器方法,反之亦然.

所有这些库都基于以下事实:node.js允许您以低级方式处理所有事情,并且与客户端的通信流畅流畅,因为您在任一端使用了相同的语言.

对我来说,卖点是我在MVC库上有相同的 backbone.js 客户端和服务器.我所有的模型代码都被重复使用.客户端和服务器上的模型通过 now.js 进行简单同步.

我的数据库访问由摇篮(或 EJS 完成的,我的视图在客户端和服务器之间共享.只是有大量的代码重用,并且我的整个Web开发都是在JavaScript中完成的,这意味着我不必切换我的编码范例或样式.

我也没有决定如何处理服务器上存在的内容与客户端上存在的内容之间的灰色区域的麻烦,因为该灰色区域已被完全平滑并且客户端与服务器无缝集成.

如果您要编写一个复杂的动态Ajax Web应用程序,那么node.js是一个理想的选择.如果您要拥有一个静态网站,那么node.js是一个理想的选择(您可以在20分钟内完成设置).

如果您要编写服务器繁重的网站,而客户端功能和回发很少,那么最好使用php或ASP.NET.但是,如果这样做,您应该研究更多动态客户端功能并使用Ajax.

I'm trying to get my head around where Node fits in. It's niche, so to say... What obstacles is Node aiming to provide a ramp for?

I've read through the examples and seen a few demonstration videos. And it all looks very slick... Creating a simple web server; creating a simple TCP/IP chat server; using Node as an JSON-based front for a database server... But where does it fit in? I mean, except for the last example, what is there to do with Node?

I guess what I'm asking is this: What would you use Node for? And why?

解决方案

Convince the Boss

List of reason to use node:

  • Speed. V8 is fast. It's faster then python, it's faster then php.
  • Evented IO. IO done properly. No messing about with threads, everything works nice and easily.
  • Low level web server. A good control over the abstraction in a dynamic language.
  • JavaScript. A great language with a lot of developers experience in writing asynchronous code. Development is fast and maintenance is lovely as everything can be done in one language (clientside, server-side, database access).

Libraries and tools that can be used with node.js:

  • express.js : MVC Web framework. Very lightweight. Gives you routing and views. Builds ontop of connect.js. Out of the box flexible control of views and routes with multiple css and templating engines supported. As with node.js itself it's simplistic and gives you fine grained control of your web server. Personally I find the balance between control and abstraction about right.
  • socket.io : The de-facto websocket abstraction. Lot's of graceful degradation support build in so browsers without websocket use comet techniques or a flash bridge. Allows you to talk between client and server in a no-hassle, easy and realtime manner.
  • now.js : Builds on top of socket.io and gives you a synchronized name space across client and server. Allows you to trivially call server methods from the client or vice versa.

All of these libraries are based on the fact that node.js allows you to handle everything on a low level manner and that communication with the client is smooth and streamlined because you use the same language on either end.

The selling point for me is that I have the same MVC library backbone.js on the client and the server. All my model code is re-used. The models on the client and the server are synchronized trivially over now.js.

My database access is driven by cradle (or mongoose) which is all written in JavaScript. Actually my MVC ties directly into the database and seamlessly saves my models. The models define useful methods like save and fetch to do persistent database storage. I don't manually touch the database because my MVC allows me to plug-in in a database driver to do this for me.

The rendering of my templates is done with EJS, my views are shared among the client and the server. There is simply a large amount of code-reuse and my entire web development is done in JavaScript which means I don't have to switch my coding paradigm or style.

Nor do I have trouble deciding how I should handle the grey area between what lives on the server and what lives on the client because that grey area has been completely smoothed over and the client and server integrate seamlessly.

If you're going to write a complex dynamic ajax web application then node.js is a perfect candidate. If you're going to have a static website then node.js is a perfect candidate (You set it up in 20 minutes).

If you're going to write a server heavy website with little client side functionality and postbacks then maybe you're better off using php or ASP.NET. But if you're doing that you should looking into more dynamic client side functionality and using ajax.

这篇关于Node.js的用途-旨在为之提供坡度的障碍是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆