Nodejs and custom modules on windows

It has been a long time, I was planning to hit on Node.js, but I got stuck with other topics and somehow it slipped my mind. Few days back, I thought to give it a try and check what Node.js offers. I like the idea of using JavaScript to write code for Node.js (After all thats my first programming language and the most fav. language 😛 ).
The first baby step with “Hello World” and writing your own web server, made me comfortable and I realised its so much of fun to write code for nodejs as you have to just learn the APIs and start modularizing them. As soon as I started making the progress, I found an example making use of Node.js’s custom module “connect”.

To kill the cat of curiosity, I just followed the steps to install the custom module (I used npm) and it got downloaded successfully. To begin with, I just recoded the “Hello World” program and tried to ran it. But unfortunately, I ended up getting following error.
Node custom modules error
I didnt realize what went wrong, as I followed all the steps to install custom module. I tried copy pasting the module from node_modules directory to others, but it didn’t work. Some of the posts suggested to copy the custom module to the directory, where code is located. Personally, I didnt like the idea of doing it as I wanted the custom modules to be located globally. After doing bit googling, someone stated that NODE_PATH should be set in order to use custom modules, but it wasn’t clear whether it should be node installation path or something else. After few tryout, I could able to solve the riddle and found the custom modules working.
The step is pretty simple, Just create an environment variable NODE_PATH and point it to “Node installaton directory + node_modules”. Here is an example
NODE_PATH=C:\Program Files\nodejs\node_modules
It worked for me like charm, hope it helps you, till then happy noding.. oops I mean happy coding 🙂

By Carbon Rider

Hi this is Yogesh, welcome to my world. Being passionate about learning new technologies and building frameworks, I end up spending most of my time in front of computer. But over last few months, I realised apart from being good coder and designer (Yes I am) I have something hidden in me. And thats called ART.

Leave a Reply