I am in the process of playing with Bluemix and part of the reason or this is to learn more about node.js. It is really cool to learn something new and also to broaden the mind. But I digress – Node Package Manager (npm) makes using node.js so simple it is mind boggling…
Without going into masses of detail on node.js (which I might at some point) here is the simple example of what I am trying to do and why npm is so cool. Node Package Manager (npm) allows you to install any node “module” or code component library, very easily and with the minimum of effort.
I run node.js on my windows machine within a certain directory. I am looking into CORS enable one of my Bluemix applications so I am messing with the cors module in node.
Here is my directory structure to start with. It is only a simple hello world app but for the sake of this demonstration it is all I need.
Within node_modules we have the following packages which are the modules I used as I was learning the hello world example.
Adding a new module using npm could not be simpler
To add “cors” to my application I open the hello-world directory in a command prompt (Shift right click)
I install cors with the simple “npm install cors” (yes Ryan I used a Command Line Interface)
The files are downloaded from the npm website and they are added to my directory structure
and it is as simple as that. I now have all the cors code which can be accessed by my application.
It only struck me this morning as to the sheer brilliance of this as I “muscle memory” did this to install a new module because it occurred to me I needed it. Simplicity is a thing of beauty to me.
- I wanted to install a new module
- The npm architecture with node centralizes all the code modules you need
- I did not need to know where to look for the cors package existed
- I found my example of how to use CORS online
- I added the code module I needed to my application with 3 words
- so cool 🙂