Node.js和socket.io,它是纯JavaScript吗? [英] Nodejs and socket.io, is it pure javascript?

查看:62
本文介绍了Node.js和socket.io,它是纯JavaScript吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用nodejs和socket.io ...

I'm starting to use nodejs and socket.io...

是纯JavaScript还是我必须学习JQuery或MOntools之类的框架?

Is it pure javascript or do i have to learn a framework like JQuery or MOntools ?

谢谢!

推荐答案

node.js是纯JavaScript.

node.js is pure javascript.

是的,您确实需要学习node.js,因为它是您的服务器端IO库.而且,您无需学习jQuery或MooTools即可进行服务器端开发.

Yes you do need to learn node.js because its your server-side IO library. And no you do not need to learn jQuery or MooTools for server-side development.

在node.js社区中,非常强调使用第三方库来实现所需的功能.当前没有为节点设置框架.

Within the node.js community there is a strong emphasis on using 3rd party libraries to achieve what you want. There are currently no frameworks set up for node.

几个值得学习的图书馆

  • 表达 路由,查看引擎和控制器(MVC的一半)

Express是一个轻量级的MVC库,它建立在 connect 的之上.这使您可以访问路由库和视图引擎.与 EJS express-controllers ,这是处理REST样式路由的好方法网址.

Express is a lightweight MVC library that builds ontop of connect. This gives you access to a Routing library and a view engine. When used in combination with EJS or Jade it will allow you to set up your node.js code to handle incoming routes individually and rendering data from templates. I would also recommend looking at express-controllers which is a great way to handle REST style routing of your urls.

现在是socket.io之上的抽象.它在客户端和服务器之间提供了一个共享"名称空间.这使RPC变得微不足道.只需在服务器上将函数声明为now的属性,然后从客户端调用它即可.现在为您处理所有的socket.io通信.

now is an abstraction on-top of socket.io. It offers a "shared" namespace between client and server. This make RPC trivial. Simply declare a function as a property of now on the server and call it from the client. Now handles all the socket.io communication for you.

Cradle是一种抽象,允许您与 couchdb 进行交互.如果您打算使用节点,建议您使用NoSQL数据库,例如沙发或 mongodb (尝试

Cradle is an abstraction that allows you to interact with couchdb. If your going to use node I recommend you use a NoSQL database like couch or mongodb (Try mongoose if your using mongo).

一个很棒的实用程序库,允许您以功能样式(例如python或ruby)进行编码.尽管大多数功能已经是ES5的一部分,但还是强烈建议这样做.在客户端上使用它来模拟ES5也是一个很大的优势

An awesome utility library that allows you to code in a functional style (think python or ruby). This is highly recommended although most of the features are already part of ES5. Using this on the client to emulate ES5 is also a great advantage

  • 骨干 集合和模型(MVC的另一半)

Backbone是轻量级的MVC抽象.这使您可以使用更常见的MVC构造.对于node.js本身,我建议使用 Backbone.Model Backbone.Sync 来与您选择的数据库抽象进行交互,这实际上使Backbone进入ORM.一个可靠的替代方法是 Spine

Backbone is a lightweight MVC abstraction. This allows you to use more commonly known MVC constructs. For node.js itself I would recommend using Backbone.Model and Backbone.Collection and having express handle the view rendering (but populating the views with data from collections and models). You can also easily overwrite Backbone.Sync to interact with your database abstraction of choice which virtually turns Backbone into an ORM. A solid alternative would be Spine

未来为您提供了一个promises API.这对于编写可管理的可读代码非常有用.它还使您无法将回调嵌套5层.图书馆本身规模很大.它还提供了不错的抽象,用于按顺序运行异步回调,并在末尾与回调处理程序并行运行它们.

Futures gives you a promises API. This is great for writing manageable readable code. It also stops you from nesting callbacks 5 layers deep. The library itself extensive. It also provides nice abstractions for running asynchronous callbacks in sequence, and for running them in parallel with a callback handler at the end.

3个月后

完成一些项目后,我仍然建议您速递.但是.

After having done a few projects, I would still recommend express. However.

我不推荐

  • 现在.为什么?它挡住了它,泄漏了.改用 socket.io .
  • 摇篮.为什么?它有一些难以解决的恶臭案例,请改用request.
  • 下划线.为什么?只是不需要. ES5具有足够的表现力
  • 骨干/脊柱.为什么?它泄漏了,它挡住了路.它不是为服务器设计的
  • 未来.为什么?太过分了.您不需要它.改为使用之后.
  • express-controllers.这是一个泄漏性的抽象,它不起作用.
  • now. Why? It get's in the way, it leaks. Use socket.io instead.
  • cradle. Why? It has edge case bugs that are a nightmare to debug, use request instead.
  • underscore. Why? It's just not needed. ES5 is expressive enough
  • backbone/spine. Why? It leaks, it get's in the way. It's just not designed for the server
  • futures. Why? It's overkill. you don't need it. Use after instead.
  • express-controllers. It's a leaky abstraction, it doesn't work.

我会推荐的东西.

  • unit tests (vows-is)
  • hot code reloading (forever/nodemon)
  • scaling architecture (cluster/hook.io

这篇关于Node.js和socket.io,它是纯JavaScript吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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