Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

linux - Nodejs and socket.io, is it pure javascript?

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

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

Thank you!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

node.js is pure javascript.

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.

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.

A couple of libraries worth learning are

  • express The Routing, View engine and Controllers (Half of MVC)

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.

  • now The websocket library

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

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

  • backbone The Collections and Models (Other half of MVC)

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

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 Months later

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

I do not recommend

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

Things I would recommend.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...