Skip to content
Newer
Older
100644 82 lines (49 sloc) 2.51 KB
e731d4f @ericz adding readme
ericz authored Jul 22, 2011
1 Get NowJS http://www.nowjs.com/
2 =========
3 NowJS is a Node.js module. The client javascript (now.js) is served by the NowJS server.
4
5
6 <a href="https://github.com/Flotype/now/">Go to Github</a> or
7 <a href="https://github.com/Flotype/now/tarball/master">Download the tgz</a>
8
9
10 Install From npm
11 ----------------
12
13 `npm install now`
14
15
16
17 NowJS uses the excellent <a href="https://github.com/LearnBoost/Socket.IO-node">socket.io</a> and <a href="https://github.com/isaacs/node-proxy">node-proxy</a> libraries and portions of <a href="https://github.com/substack/node-sesame">sesame</a>. <a href="https://github.com/douglascrockford/JSON-js">json2.js</a> is integrated in nowUtil.js
18
19
20 2 Step Setup
21 ==============
22
23 **1. On the server**
24
25
26 var httpServer = require('http').createServer(function(req, response){ /* Serve your static files */ })
27 httpServer.listen(8080);
28
29 var nowjs = require("now");
30 var everyone = nowjs.initialize(httpServer);
31
32 everyone.now.logStuff = function(msg){
33 console.log(msg);
34 }
35
36 **2. On the client**
37 <pre><code>
38 &lt;script type="text/javascript" src="http://localhost:8080/nowjs/now.js">&lt;/script>
39
40 &lt;script type="text/javascript"&gt;
41 now.ready(function(){
42 // "Hello World!" will print on server
43 now.logStuff("Hello World!");
44 });
45 &lt;/script>
46 </code></pre>
47
48 FAQ
49 -------
50
51 **Q: Can I pass in a callback or closure, for example, if the remote function is asynchronous?**
52
53 A: Yes. This is 100% supported
54
55
56 **Q: How do I use NowJS with [Express](https://github.com/visionmedia/express)?**
57
58 A: Very easily.
59 var app = express.createServer();
60 app.listen(3000);
61 var everyone = require("now").initialize(app);
62
63
64 **Q: Error: " SyntaxError: Unexpected token *" / Can I statically host the now.js file?**
65
66 A: On the client side, make sure you link to now.js like this
67
68 <script src="http://myserver:myport/nowjs/now.js"></script>
69
70 You do not need to host the file /nowjs/now.js. It is automatically hosted by the NowJS using the http server you pass into the .initialize(...) in your server code. If you choose to host now.js yourself, you can, but **do not use the version in github repo** you MUST save the file at `http://myserver:myport/nowjs/now.js` and host that, because it is automatically configured for your server.
71
72 Further Reading
73 ---------------
74
75 Now that you have NowJS, try the NowJS [User Manual](http://nowjs.com/doc) and [Quick Chat Example](http://nowjs.com/guide)
76
77 Have more questions? Please contact us:
78 Email: team@nowjs.com
79
80 IRC: #nowjs on freenode
81
82 Twitter: @NowJSTeam
Something went wrong with that request. Please try again.