Node JS

NPM Demystified Part-1 : npm install explained in detail.

In the previous chapter, we managed to run node application with inbuilt node modules. This chapter we will include some more external node module into our application. Basically npm install explained in detail.

For now, our index.js file will look like:

const http = require('http');

const hostname = 'localhost';
const port = 3000;
const server = http.createServer((req, res) => {
res.end('Hello World\n');
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);

Before using external node modules, we need to install those node modules into our application.

☝☝Question: How can I install node modules in our application?
Don’t Worry, It is very simple you need to use following command npm install <package_name>.

☝☝Question: Where I should search for external node modules?
You can search for node modules in this URL There are multiple node modules available for the same purpose and you can use which one suits you well.

☝☝Question: Can I write my own node modules and able to push in to npm website?
Yes, You can write your own node modules and you can push your node modules into npm website. So that other developer can use your code. We will see how to do it in the separate post.

Install external npm module:

Now I’m planning to install lodash modules. One of the popular module in node.

npm home page

When you search lodash in the npm website, it will return multiple modules and we are going to use lodash. Let’s install it.

npm install lodash –save

It takes less than a minute for installation based on your network bandwidth.

???Great!! you have installed external node module!

Lets check our application folder structure now.

If node modules installed successfully, then you can able to see the node_modules folder in the parent directory and inside node_modules you can see lodash folder available.

node_modules folder is created automatically when we do npm install so we are good now.

☝☝Question: Everything looks good! But why you have used –save option while installing lodash module?
Let’s see why we need to put –save in during installation.

Let’s check our package.json

  "name": "nodeapp",
  "version": "1.0.0",
  "description": "My node app",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  "author": "",
  "license": "ISC",
  "dependencies": {
    "lodash": "^4.17.4"

When we do –save, installed node module will be added as a dependency for our application. It is something similar to adding Jar as the dependency in maven file.

Please share your comments or questions in the below comment section!!???