NPM enables us to do 3 things:
NPM calles the reusable code a package. A package is essentially is a folder that contains a js code. Other names are modules and dependecies but, all of these are the same thing.
There is no quality control in npm. So, anyone can publish anything and its upto us to sniff out the empty and useless packages.
A good measure of a quality package is the amount of weekly downloades. If the number is high, it is a battle tested module.
Its much simpler to use npm, because when we install node we also install npm. And because of this we have access to npm global command. Check your npm version using:
npm —v
We can install package as a local dependency(only for a specific project) or use it as a global dependency(use it in all projects).


Now, if I run npm init:

You can give a package name here. By defaut it will be the folder name.

This will create the package.json like:

Now, why do we need package.json?
If I want to install the local package, which will be stored as a dependency. For example if I install lodash package like:

As, you can see it created a loadash package under dependencies in the package.json. It also created a node_modules folder which will contain the actual package. Please put this folder in .gitignore when pushing the project to github.

Now, this was a small package. But if you try to install something like bootstap:

Note: Here we not only have lodash and bootstrap but also properjs(since, bootstrap uses it).

So, anyone with the help of package.json can run your code. They don’t need your node_modules, they can just run the command “npm install” to create there own node_modules. This makes it very easy to share code with other developers. So, we can share the code without dragging the massive node_modules folder with us.
Now, lets install the dependency we will be using for the rest of our course: nodemon.
nodemon is a tool that helps develop Node.js based applications by automatically restarting the node application when file changes in the directory are detected.
We can install nodemon as dev dependency like:

Now, why do we want to install it as a dev dependency?
So, what other packages should we install as dev dependencies?

So, as you can see using scripts we can create something like a start script so, we can simply use npm start to run the node project.
Note: npm start is a command command that can be run easily. But, for other you have to give the whole command including run. For eg,

Here you can see we are using “run” in the command.
Now, note here as I change the small thing in my app.js nodemon automatically restarts the node. This is very usefull.


Now, you can see in package.json we also have version control. We can edit the versions. Since, newer versions may contain some bugs.
Now, the package-lock.json tracks the versions of dependencies of dependencies.

As, you can see here it is locking the versions of the underlying dependencies of the dependency we installed.