Contents hide 1) >_ npm 2) Setting Up npm 3) Package.json 4) Installing Specific Versions 5) Uninstall Package 6) Install Latest Version of npm Getting Started With Node Package Manager npm. In this tutorial, we will see how to setup npm. >_ npm npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you’re sharing. Node Package Manager contains lots of package with the different set of code which been shared worldwide. You can access those packages just typing a single command with package-name.As all package name are unique. Let’s Get Into It: Setting Up npm For setting up the npm you must first set up the project, or else you also can just create a simple project folder and setup npm in it. So access your custom project directory through the terminal and input the command as given below: $ npm init the terminal leads to some procedure to create a package.json file. After setting up all the answer it automatically creates the package.json file with the given content e.g. $ npm init name: (geekstrick Demo) geekstrick version: (1.0.0) 0.0.1 // app version description: demo entry point: (index.js) app.js test command: git repository: url //repository URL keywords: npm tutorial author: rehmaan ali license: (ISC) ISC This will create the JSON file named as package.json with the data containing the dependencies -modules packages, app or project details, version of the project etc. Package.json This is the file which the npm works on. Package.JSON file contains the details of the packages, author, license. The main part is the packages and their different versions. npm commands control or saves those packages in the project. so after setting up the project, you need just one command to install all the dependencies containing in the package.JSON { "name": "geekstrick", "version": "0.0.1", "description": "demo", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", "url": "url" // url goes here }, "keywords": [ "npm", "tutorial" ], "author": "rehmaan ali", "license": "ISC" } Here it created the JSON file. But we are not finished here. The main part is to install dependencies. So if you need to add some of the dependencies you just are just one command ahead. So, for installing some dependency use the following command. e.g. If we want to add the node express module. $ npm install express This will install you express package in your project. But it don’t adds up the package details in your package.json file. So for installing the package in your project and so in JSON file use the following command: $ npm install express --save package.json "dependencies": { "express": "^4.15.3" } Installing Specific Versions The package has its different versions denoted by 3 numbers like 1.8.3 Where : 1.8.3 is the major version 1.8.3 is the minor version 1.8.3 is the revision or patch number Patch Number: It’s incremented when it make a bug fix or performance improvement to the product. Some a thing that doesn’t change functionality, so it changes to 1.8.4. Minor Number: It’s incremented when there are new features involved and changed to 1.9.0, In this, there is no functionality is broken but the new functionality is added. Major Number: In case it breaks the functionality it takes changes to a major version, so it changes to 2.0.0 For installing the specific version of the package we can use the following command to get that version: $ npm install [email protected] --save As if you want to install the latest version of 1.8 u can use ‘ x ‘ instea a of number or just delete the patch number. $ npm install [email protected] --save --save-exact // OR $ npm install [email protected] --save --save-exact Uninstall Package Now what if you want to uninstall the package from the project, it is as simple as it is. command for uninstalling the package. just use uninstall instade of install $ npm uninstall express --save Install Latest Version of npm You can install the latest version of npm by typing just one command. But you have to run the command through command pad but on administrator privilages. As it installs globally it will mess up the npm, and its leds to reinstall the npm package from beginning. So for installing the latest version of npm the command is : $ npm install [email protected] -g // -g Install's the package globally You can find out more tricks to play with npm Here Share this:TwitterFacebookRedditLinkedInWhatsAppPrintTumblr Related Tags: Commands, nodejs, npm