How do the two compare to each other?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Keeping track of variable instances
NowJS team member here. Correction to andref's answer:
NowJS fully supports "Remote Method Invocation". You can pass functions as arguments in remote calls and you can have functions as return values as well.
These functions are wrapped by NowJS just as they are in DNode so that they are executed on the machine on which the function was defined. This makes it easy to expose new functions to the remote end, just like in DNode.
P.S. Additionally, I don't know if andref meant to imply that remote calls are only asynchronous on DNode. Remote calls are also async on NowJS. They do not block your code.
TL;DR
DNode
connect
;NowJS
Conclusion
NowJS is more of a toy right now -- but keep a watch as it matures. For serious stuff, maybe go with DNode. For a more detailed review of these libraries, read along.
DNode
DNode provides a Remote Method Invocation framework. Both the client and server can expose functions to each other.
The function that is passed to
DNode()
is a handler not unlike the one passed tohttp.createServer
. It has two parameters:client
can be used to access the functions exported by the client andconnection
can be used to handle connection-related events:The exported methods can be passed anything, including functions. They are properly wrapped as proxies by DNode and can be called back at the other endpoint. This is fundamental: DNode is fully asynchronous; it does not block while waiting for a remote method to return:
Callbacks must be passed around in order to receive responses from the other endpoint. Complicated conversations can become unreadable quite fast. This question discusses possible solutions for this problem.
The DNode client can be a script running inside a Node instance or can be embedded inside a webpage. In this case, it will only connect to the server that served the webpage. Connect is of great assistance in this case. This scenario was tested with all modern browsers and with Internet Explorer 5.5 and 7.
DNode was started less than a year ago, on June 2010. It's as mature as a Node library can be. In my tests, I found no obvious issues.
NowJS
NowJS provides a kind of magic API that borders on being cute. The server has an
everyone.now
scope. Everything that is put insideeveryone.now
becomes visible to every client through theirnow
scope.This code, on the server, will share an
echo
function with every client that writes a message to the server console:When a server-side "shared" function runs,
this
will have anow
attribute that is specific to the client that made that call.Functions in NowJS can have return values. To get them, a callback must be passed:
This has an implication if you want to pass a callback as an honest argument (not to collect a return value) -- one must always pass the return value collector, or NowJS may get confused. According to the developers, this way of retrieving the return value with an implicit callback will probably change in the future:
And this is it for the NowJS API. Well, actually there are 3 more functions that can be used to detect client connection and disconnection. I don't know why they didn't expose these features using
EventEmitter
, though.Unlike DNode, NowJS requires that the client be a script running inside a web browser. The page containing the script must be served by the same Node that is running the server.
On the server side, NowJS also needs an http server listening. It must be passed when initializing NowJS:
NowJS first commit is from a couple weeks ago (Mar 2011). As such, expect it to be buggy. I found issues myself while writing this answer. Also expect its API to change a lot.
On the positive side, the developers are very accessible -- Eric even guided me to making callbacks work. The source code is not documented, but is fortunately simple and short and the user guide and examples are enough to get one started.
Haven't tried Dnode so my answer is not a comparison. But I would like to put forth few experiences using nowjs.
Nowjs is based on socket.io which is quite buggy. I frequently experience session time-outs, disconnects and
now.ready
event firing multiple times in a short duration. Check out this issue on nowjs github page.Also I found using websockets unviable on certain platforms, however this can be circumvented by explicitly disabling websockets.
I had planned creating a production app using nowjs but it seems its not mature enough to be relied upon. I will try dnode if it serves my purpose, else I will switch to plain-old
express
.Update:
Nowjs seems to be scrapped. No commits since 8 months.