NPM Novice to Ninja guide - NPM Tutorial

NPM Novice to Ninja guide - NPM Tutorial

In this tutorial we are going to learn NPM – Node Package Manager from step-by-step beginner to advance level.

So let’s get started…

What is NPM?

- NPM is Stands for ‘Node Package Manager’

- NPM is a package manager for Node.js with hundreds of thousands of packages.

- NPM allows Easily installation modules/packages on your system, Modules are basically Javascript libraries-

-The main purpose of using NPM is automated dependency and package management. It means that you can specify all your project’s dependencies inside your package.json file, then any time you (or anyone else) needs to get started with your project they can just run npm installand immediately have all of the dependencies installed.

By using NPM package.json you can also specify what versions your project depends upon to prevent updates from breaking your project.

What is Package.json File?

-Manifest file with app info which have information like project_name, author, version etc…

-Most important thing is it holds all your project dependencies(Modules) with name and version.

-Specify if the version should be updated or not.

-Easily create with “npm init” command

How to install NPM?

fortunately, if you have already installed Node.js then you no need to install because it is Pre-installed with Node.js

To check whether or not you have NPM installed, visiting your command line or Terminal and type:

npm -v

if you don’t have installed then simply install by Visiting Node.js website and download and Install it.

That’s it now you are able to use NPM in your Project.

now take a look at following some basic commands for NPM:

1. To Create Package.json file in your terminal type:

npm init

 It will create a simple package.json file in your directory and it will look like that:

 

{
"name": "npm",
"version": "1.0.0",
"description": "Demo_NPM",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jignesh Kumar",
"license": "ISC"
}

 2. To Create Package.json without asking any question:

npm init --yes

 

3. Get Package.json properties with cmd:

npm get init-author-name

4.Change package.json properties with CMD:

npm set init-license "MIT"

5. To delete package.json properties:

npm  config delete init-author-name

6. To Install all dependencies from package.json file:

npm install

7. To Install specify dependencies, for example, we want to install ‘lodash’ then type:

npm install lodash

 8. To install dependencies with specific version:

npm install loadash@4.17.3

9. To update to the latest version:

npm update loadash

 10. To Save Package to package.json file:

npm install loadash@4.17.3 --save

 

11. To remove dependencies:

npm uninstall lodash

 12.list out all installed packages:

npm list

 

13.list only the main directory of installed packages:

npm list --depth 0

 That’s all about NPM now you can use NPM with the given command in your project.

so that’s why NPM Makes it easy for developers to share & reuse code.

Conclusion:

Thanks for reading.

Do let me know If you face any difficulties please feel free to comment below we love to help you. if you have any feedback suggestions then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook and Twitter

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment