Node Package Manager🦆🦆🦆🦆
Tags: webdev, javascript, beginners, programming
Published: 2023-11-07 06:04:17

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
```cli
npm i nodemon -g
```

`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.json `configuration

#### Example of installing the package locally 

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

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. 

```cli
npm i date-fns
```
now this `date-fns` will be installed as a dependencies to the `package.json` . This can be seen in the `package.json `file 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.
```cli
npm i nodemon -D
```


### How to configure Scripts in `package.json`

```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"
  }
}
```
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/

```json
  "devDependencies": {
    "nodemon": "^3.0.1" 
  }
```
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 ?

```cli
npm i uuid@9.3.1
```

to update

```cli
npm update uuid
```

to uninstall

```cli
npm uninstall uuid
```

```cli
npm rm uuid
```

to uninstall from dev dependencies
```cli
npm rm nodemon -D
```
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.