Pregunta

Im playing around with node.js and now.js. Everything works fine. But i would like to make a simple client that i can run from the command-line (so without the browser).

http://nowjs.com/doc/example

In the example a HTML page gets served, and that page includes the now.js file, which creates the magic 'now' object. But on a commmand-line there is no such thing.

For the server i have running (helloworld_server.js)

And the client helloworld_client.js i have:

// client.js
var nowjs = require("now");

// now i need to connect to the server (127.0.0.1:8080)
// so i i need a server object?

server = ????

var everyone = nowjs.initialize(server);

everyone.now.distributeMessage('hi!');

So how do i obtain the 'now' object?

¿Fue útil?

Solución

OK, got it. Once you installed now

npm install now

it creates a node_modules folder, inside you see folders for each extension. Deeper you find:

./node_modules/now/examples

and there is the nodeclient_example folder

./node_modules/now/examples/nodeclient_example

its pretty clear from there, but those curious, this is the magic you need:

var nowjs = require('../../lib/nodeclient/now.js');
var now = nowjs.nowInitialize('http://localhost:8080');

and there it it the 'magic' now object

make sure you install :

npm install socket.io-client

otherwise it wasn't working for me!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top