DEV Community

Cover image for Node Package Manager🦆🦆🦆🦆
Tanmay Agrawal
Tanmay Agrawal

Posted on

Node Package Manager🦆🦆🦆🦆

The documentation for the node module is given in the following documentation link
NPM stands for Node Package Manager
https://www.npmjs.com/

Example of installing the NPM module nodemon globally

npm i nodemon -g
Enter fullscreen mode Exit fullscreen mode

nodemon basically automatically restarts the server when we save the file on making changes. by default it watch index.js . But it can be change in package.jsonconfiguration

Example of installing the package locally

In order to do that, we have to firs initialize the npm,

npm init
Enter fullscreen mode Exit fullscreen mode

This will create the folder package.json
This file is important, because it is what npm read what dependencies is important to install for the project.

npm i date-fns
Enter fullscreen mode Exit fullscreen mode

now this date-fns will be installed as a dependencies to the package.json . This can be seen in the package.jsonfile in the key dependencies added.

Now at this point it can be seen that another folder is created node_modules now this folder has additional dependencies on the package module that we have just installed, this folder is the huge chunk of data, we usually want to avoid it to publish when we are making a repo.
so it is best to add .gitignore file and then mention the name of the node_modules folder name in it so it gets ignored while we make the repository and push into the branch.

Installing a package as a dev dependencies

The nodemon as we have installed above was a global dependencies, but we can also deploy it as an dev dependencies.

npm i nodemon -D
Enter fullscreen mode Exit fullscreen mode

How to configure Scripts in package.json

{
  "name": "file-system-module",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "nodemon server",
    "start": "node server.js"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "nodemon": "^3.0.1"
  }
}
Enter fullscreen mode Exit fullscreen mode

In the above example, the snippet shown is from the package.json notice the scripts there,
"dev" : "nodemon server" is added, The nodemon is added as the dev dependencies.
*What this line does is when we do npm run dev it will basically do nodemon server *

Semantic Versioning

Read more here https://semver.org/

  "devDependencies": {
    "nodemon": "^3.0.1" 
  }
Enter fullscreen mode Exit fullscreen mode

here ^3.0.1 represents the version, 3 is the major version 0 is the minor version and the 1 is the patch recently installed. Note we don't want to change the major version, because this can create the breaking impact on the code.

^ this means do not change the major version but can update the minor version.
~ this means do not change the major and minor version but can update the patches.

How to install a specific version ?

npm i uuid@9.3.1
Enter fullscreen mode Exit fullscreen mode

to update

npm update uuid
Enter fullscreen mode Exit fullscreen mode

to uninstall

npm uninstall uuid
Enter fullscreen mode Exit fullscreen mode
npm rm uuid
Enter fullscreen mode Exit fullscreen mode

to uninstall from dev dependencies

npm rm nodemon -D
Enter fullscreen mode Exit fullscreen mode

Notice to remove the dev dependencies from the package.json file as well, it is a good practice to always check.

So this is most of it, I am just sharing what I am learning everyday, So making notes and making them in such a way that the notes get well documented, helps me to make some useful posts on this platform. I hope my notes will also helps the new learners who have just started their journey in web dev like me.

Also, I would like to announce that I have just finished courses on JavaScript and I am willing to collaborate on projects, If you are also a beginner or intermediate, just comment, and we can create a discord server and discuss small project ideas together.

Top comments (0)