now.js file => replace fileServer with "fs"?

39 views
Skip to first unread message

christianstrang

unread,
Dec 30, 2011, 10:52:28 AM12/30/11
to nowjs
If I run the "quick example" from here: http://nowjs.com/doc/example I
receive the error "cannot find module .fileServer" which is linked in
the now.js file.
Do I have to replace "fileServer" with "fs" or did I install node.js
wrong? Is fileServer a module which is installed together with Now?

Eric Zhang

unread,
Dec 30, 2011, 1:05:53 PM12/30/11
to no...@googlegroups.com
Hi christian,

fileServer is part of the NowJS library package. How did you install NowJS? If you used npm, and ran the command `npm install now` then fileServer should've automatically been included.


Eric
--
Co-Founder @ Flotype, makers of NowJS

christianstrang

unread,
Dec 30, 2011, 1:47:00 PM12/30/11
to nowjs
Mh.. here is how I installed it and what I got:

root@vmanager433:/var/www/virtual/domain.com/htdocs# npm install now
npm WARN node-...@0.5.2 package.json: bugs['web'] should probably be
bugs['url']

> node-...@0.5.2 install /var/www/virtual/domain.com/htdocs/node_modules/now/node_modules/node-proxy
> make

BUILDING: C++ Component
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.027s)
Waf: Entering directory `/var/www/virtual/domain.com/htdocs/
node_modules/now/node_modules/node-proxy/src/build'
[1/2] cxx: node-proxy.cc -> build/Release/node-proxy_1.o
[2/2] cxx_link: build/Release/node-proxy_1.o -> build/Release/node-
proxy.node
Waf: Leaving directory `/var/www/virtual/domain.com/htdocs/
node_modules/now/node_modules/node-proxy/src/build'
'build' finished successfully (0.671s)
n...@0.7.6 ./node_modules/now
âââ node-...@0.5.2

Eric Zhang

unread,
Dec 31, 2011, 2:36:02 AM12/31/11
to no...@googlegroups.com
Hmm that looks correct. Can you send me the output the code of your program?


Eric

christianstrang

unread,
Dec 31, 2011, 5:45:48 AM12/31/11
to nowjs
This is my code in the server.js file (which lies in /var/www/virtual/
domain.com/htdocs/helloworld):

var html = require('fs').readFileSync(__dirname+'/index.html');
var server = require('http').createServer(function(req, res){
res.end(html);
});
server.listen(8080);

var nowjs = require("../now"); //the now.js file is one folder up
var everyone = nowjs.initialize(server);

everyone.now.distributeMessage = function(message){
everyone.now.receiveMessage(this.now.name, message);
};

If I call "node server.js" I receive the following output:

node.js:201
throw e; // process.nextTick error, or 'error' event on first
tick
^
Error: Cannot find module './fileServer'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous> (/var/www/virtual/domain.com/htdocs/now.js:
2:18)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)

On Dec 31, 8:36 am, Eric Zhang <e...@nowjs.com> wrote:
> Hmm that looks correct. Can you send me the output the code of your program?
>
> Eric
>
> On Fri, Dec 30, 2011 at 10:47 AM, christianstrang <g...@christianstrang.de>wrote:
>
>
>
>
>
>
>
>
>
> > Mh.. here is how I installed it and what I got:
>
> > root@vmanager433:/var/www/virtual/domain.com/htdocs# npm install now
> > npm WARN node-pr...@0.5.2 package.json: bugs['web'] should probably be
> > bugs['url']
>
> > > node-pr...@0.5.2 install /var/www/virtual/
> > domain.com/htdocs/node_modules/now/node_modules/node-proxy
> > > make
>
> > BUILDING: C++ Component
> > Checking for program g++ or c++          : /usr/bin/g++
> > Checking for program cpp                 : /usr/bin/cpp
> > Checking for program ar                  : /usr/bin/ar
> > Checking for program ranlib              : /usr/bin/ranlib
> > Checking for g++                         : ok
> > Checking for node path                   : not found
> > Checking for node prefix                 : ok /usr/local
> > 'configure' finished successfully (0.027s)
> > Waf: Entering directory `/var/www/virtual/domain.com/htdocs/
> > node_modules/now/node_modules/node-proxy/src/build'
> > [1/2] cxx: node-proxy.cc -> build/Release/node-proxy_1.o
> > [2/2] cxx_link: build/Release/node-proxy_1.o -> build/Release/node-
> > proxy.node
> > Waf: Leaving directory `/var/www/virtual/domain.com/htdocs/
> > node_modules/now/node_modules/node-proxy/src/build'
> > 'build' finished successfully (0.671s)
> > n...@0.7.6 ./node_modules/now
> > âââ node-pr...@0.5.2

Eric Zhang

unread,
Dec 31, 2011, 5:51:05 AM12/31/11
to no...@googlegroups.com
Hi Christian,


Once you npm install now, you no longer need to require the relative path to the now folder, but rather the keyword now.

So your code should look like `var nowjs = require('now');`

Note that you must run your node server from the same folder that you ran `npm install now`


Eric
Reply all
Reply to author
Forward
0 new messages