Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 457
Dail Avatar asked Jun 05 '11 09:06

Dail


2 Answers

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 The database library

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

  • underscore General Utility to make life easy

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 The Flow Control library

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.

  • unit tests (vows-is)
  • hot code reloading (forever/nodemon)
  • scaling architecture (cluster/hook.io
like image 180
Raynos Avatar answered Nov 12 '22 09:11

Raynos


jQuery, MooTools and Node.js are all "pure" Javascript if that's what you're asking. However, all of them are also libraries, and you will indeed have to learn their API.

You can find documentation for Node.js here.

like image 39
Frédéric Hamidi Avatar answered Nov 12 '22 08:11

Frédéric Hamidi