cover-img

What is npm and How it works?

working and useful commands mentioned in it.

19 September, 2022

17

17

0

npm - Node Package Manager

img
npm handles the packages required for a project as well as the records of all dependency, versions, and other crucial information.

How to install npm

1.

Just go to Node Js

2.

Install it with installer of your current os.

3.

And npm will install with nodejs.

4.

to check whether npm installed you can check npm version with command npm -v in your favourite terminal.

npm benefits

Pre-installed with node.js

Easily install package/module in your system.

initialize npm

1.

Open Terminal in repository you want to make your project.

2.

give command npm init to create new package.

3.

it takes some details like author , license ,git-repo etc.

4.

if you want to continue with default details which is easy and time saving to create package there is command npm init --yes.

5.

after package is created it creates the file with name package.json

install package

To install package there is command npm install package_name --save . It install package locally in that repo.

To install package globally (into your whole system) use npm install package_name -g.

--save saves the dependency **version **in package.json file.

And if you use npm install package_name --save-dev it will save package as devDependency

To uninstall package there is command npm uninstall package_name --save.

And it is similarly applicable for devDependency.

Version System


img
Generally in npm version is #.#.# this type of arrangement in which # contains numbers from 0 to unlimited.

Major Version → It is version which conatin new features than previous version and also it can break the project if use in uncompatible type.

Minor Version → This version contains minor updates and features and it can't break the project.

Patch → Patch is just some bug fixes and it doesn't break anything.

npm update

To update the package npm update package_name command is use. There are 4 parameters or flags that denote whole version system and updates which contains in dependencies section in package.json file.
img
==Symbols mention below can see in "dependencies" section after "express" package.==

^ → If you use update command in project it updates only minor version that means major version so much important for the project.

~ → It only updates the patch.

[No Sign] → You have to install exact version . e.g. if it shows 4.7.9 you have to install exactly this version. To install exact version you can use npm install package_name@versionNumber.

* → If there is only '*' in dependencies it means it updates most latest version of that package (But it is not recommended.)

Concepts use in this blog

Dependency

It is package which is essential for running the project. or the package which is use only while production.

devDependency

devDependency is dependency which is useful for testing and development.

package.json file

Contain details like author,license,script etc.

Contain all the list of dependencies.

Also contain all the version numbers.

Commands to create and handle packages

This commands are discuss in this blog and some additional commands which can also be useful.

17

17

0

Rohit Rajvaidya

Aurangabad,Maharashtra,India

FrontendDeveloper | Learning in public | #OpenSource Contributor | I have learned HTML5 and CSS3 and JavaScript currently working on ReactJS

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.