I am trying to Install a module onto my nodejs.
I have researched for tutorials to install modules, but only managed to find easy-made methods of installing via the command prompt.
I require to install the following module : https://gist.github.com/1510680 (which are javascript files). But as im new to node and all, I have no idea how to do so.
I have been searching for quite some time and I really appreciated if someone could provide a extremely lay-man guide and it would mean so much to me if someone could give me a dummy-prove step by step guide to 'install' this module ( I have never installed any module before, only recently stumbled into the world of node js and still exploring ) Help is appreciated and thanks so much.
Take a look at the node API docs. I've linked directly to the section on modules, and it includes most of what you need to know.
In a nutshell, though, you include external scripts by calling require(...)
. If the JS file you want is already in common.js form, you can simply save the file in your project folder, and use it by assigning the results of a require call to a local variable. For example, to use the SimpleCluster module you linked to, you would add the following line to your main script:
var SimpleCluster = require('./SimpleCluster.js')
The above will instantiate the file "SimpleCluster.js" found in the current directory, and anything that it exports will be accessible through your local SimpleCluster
variable. Since the gist that you linked to is in common.js format, the above should work for you without needing to modify SimpleCluster.js.
If you need more information, I'd recommend starting with nodebeginner.org. While the above advice should be sufficient to get you started, it can be brittle. If you go through Manuel Kiessling's little book (and you can read all of it online, though I'm sure he'd appreciate it if you bought it), you'll get an intro to node's package manager, NPM, which is the preferred way of handling dependencies.