Getting Started with NPM Basics.

PRANJAL AGNIHOTRI
Jul 10, 2017 · 4 min read

What NPM stands for?

Well from its official site I got this:

Needs Perl Module.

National Poetry Month.

Nobody Peels Mangoes.

Nothing Plus , More.

Normal People , MMM!

No Password Management. …And so on every time you will get something funny!!

But most commonly we call it Node Package Manager.We will talk about the Node in later part.

Why you should use NPM?

“To stay focused”.Yes let me give you an example “Suppose you were building a dynamic website or a web app and you need to make your login system to be more secure ,you can just use an npm package ‘bycrypt’ which have all the things to keep passwords more secure.By doing this you were focused on the core functionality of your web app not on the stuff which is very common and already out there!.”

This is much fun and time saving.Using others people code or sharing your code to help others is great.Like this there can be lot more examples.

Installation Overview

This installation is biased towards Windows!!!.

Download the Windows installer from Nodejs.org.

Run the installer (the .msi file which you downloaded just).

Now just accept the agreement and click Next Next and select npm package manager during setup.

Refresh your PC and its ready to be used :)

Test it : Open your command prompt and try some commands

node -v (Get the version node)

npm -v (Get the version of npm)

Yay its working :)

We can also test our Javascript code in our cmd console.Like this

Just type node and get started with nice REPL.

For exit just type .exit or ctrl+c

Installing some packages using npm

This is as interesting as it sounds.

I will later give you an example showing you how to install a package.

But first “What does Package Means”

Package is just a code library which extends your node by adding useful features. For example, the “request” package simplifies the process of making HTTP requests so you can easily get web resources from other sites.These brown boxes are package having useful code inside them.

Some commands which we will be using

  • npm install <package_name> -g
  • e.g. npm install http-server -g

By -g you are telling that you are installing package globally.

Lets install a package simple http server for local hosting

It is always good to do local hosting vs opening your .html from the file path.Because sometimes you will get this error

Chrome blocks cross origin request.

But if we do local hosting we will not get any error or not get blocked.

Installing http server like this

Its installed :)

How to use the installed package

Its simple just go to that folder where the target files are which you want to run (i m in javascript-code) then type the package name. Like this:

Its running :)

Now go to the google chrome paste any of the above three links and you will see something like this.

It opens the folder which u have specified.

Now our request will not be blocked.Yup

Now our request is not blocked.

There are over 150000 and more packages on npm so what are you waiting for explore some packages and have fun.

List of popular packages on NPM.

Hope you like it.Let me know in comments which is your favourite package.

PRANJAL AGNIHOTRI

Written by

A life-long learner who likes to code , build things and attend conferences ,hackathons , programming-contests

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade