# removing a dependency from node project

<div class="WaaZC" id="bkmrk-to-remove-a-dependen"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwipv_uxrduQAxXSUGcHHbpUF10Qo_EKegQIBhAB"><span data-huuid="16402721204245620469">To remove a dependency from a Node.js project, the `npm uninstall` command is utilized. </span><span data-huuid="16402721204245619492">This command effectively removes the package from both the `node_modules` directory and the `package.json` file, ensuring a complete removal. </span></div></div></div><div class="WaaZC" id="bkmrk-steps-to-remove-a-de"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc pyPiTc" data-hveid="CAQQAQ" data-ved="2ahUKEwipv_uxrduQAxXSUGcHHbpUF10Qo_EKegQIBBAB"><span data-huuid="16402721204245621634">Steps to remove a dependency: </span></div></div></div><div class="WaaZC" id="bkmrk-identify-the-package"><div class="RJPOee EIJn2" style="animation: none !important;">- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="16402721204245618703">**Identify the package name:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="16402721204245621822">Locate the exact name of the package you wish to remove within your project's `package.json` file under the `dependencies` or `devDependencies` sections. </span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il=""><div data-crb-p=""><div class="xFTqob"><div class="Gur8Ad" style="display: inline;"><span data-huuid="16402721204245619868">**Execute the uninstall command:** </span></div><div class="vM0jzc" style="display: inline;"><span data-huuid="16402721204245618891">Open your terminal or command prompt and navigate to the root directory of your Node.js project. </span><span data-huuid="16402721204245622010">Then, run the `npm uninstall` command followed by the package name: </span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-code"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    npm uninstall <package_name>
```

<div class="WaaZC" id="bkmrk-for-production-depen"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="18156553998514143749">**For production dependencies:** </span><span data-huuid="18156553998514146228">Use the command as shown above. </span>
- <span data-huuid="18156553998514147090">**For development dependencies:** </span><span data-huuid="18156553998514145473">If the package is a development dependency (listed under `devDependencies` in `package.json`), use the `-D` or `--save-dev` flag: </span>

</div></div><div class="WaaZC" id="bkmrk-code-1"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
        npm uninstall -D <package_name>
        # or
        npm uninstall --save-dev <package_name>
```

<div class="WaaZC" id="bkmrk-for-global-packages%3A"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="8581022453264046409">**For global packages:** </span><span data-huuid="8581022453264047100">If the package was installed globally, use the `-g` flag: </span>

</div></div><div class="WaaZC" id="bkmrk-code-2"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
        npm uninstall -g <package_name>
```

<div class="WaaZC" id="bkmrk-you-can-also-uninsta"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc" data-hveid="CCgQAQ" data-ved="2ahUKEwipv_uxrduQAxXSUGcHHbpUF10Qo_EKegQIKBAB"><span data-huuid="5458187328726950890">You can also uninstall multiple packages at once by listing them separated by spaces: </span></div></div></div><div class="WaaZC" id="bkmrk-code-3"><div class="RJPOee EIJn2" style="animation: none !important;"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc"><div class="zYSUYd"><div class="FS7GEb"><div class="dDrxod"><div class="x7ndcb">Code</div><div aria-live="polite" class="WDoJJe">  
</div></div></div></div></div></div></div></div>```
    npm uninstall <package1> <package2>
```

<div class="WaaZC" id="bkmrk-explanation%3A"><div class="RJPOee EIJn2" style="animation: none !important;"><div class="rPeykc pyPiTc" data-hveid="CCwQAQ" data-ved="2ahUKEwipv_uxrduQAxXSUGcHHbpUF10Qo_EKegQILBAB"><span data-huuid="4180915626508920186">Explanation: </span></div></div></div><div class="WaaZC" id="bkmrk-running-npm-uninstal"><div class="RJPOee EIJn2" style="animation: none !important;">- <span data-huuid="4180915626508920839">Running `npm uninstall` removes the package's files from your `node_modules` directory. </span>
- <span data-huuid="4180915626508919909">Simultaneously, it updates your `package.json` file by removing the entry for the uninstalled package from either the `dependencies` or `devDependencies` list, depending on how it was originally installed. </span><span data-huuid="4180915626508921492">This prevents the package from being reinstalled during future `npm install` operations</span>

</div></div>