Where do I have to install Now.js and express.js to access it from the web folder?
My web-folder is located here: /var/www/virtual/domain.com/htdocs and I'm using node v.0.6.6
But when I install now.js with "npm install now" in the root folder, I get an error when I want to run my server.js file:
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");
var everyone = nowjs.initialize(server);
everyone.now.distributeMessage = function(message){
everyone.now.receiveMessage(this.now.name, message);
};
Error: Cannot find module 'now'
Do I have to set the node_path somewhere? Or do I have to place the now.js file into my webfolder?
NPM will install now
and express
in the folder where you are when you execute the install command. NPM will create a folder called node_modules
and put them there. If you have a file you need to run named server.js, make sure it's at the same level as node_modules.
If you just want to install them locally and use them everywhere do it like so:
npm install now -g
The g flag stands for 'globally'.