npm

What is npm?
npm is default package manager which comes bundled with node. With node, npm gets installed. So in simple words lets see what is npm and what it does:

1- npm helps in installing packages/libraries. 
2- It can search a cloud hosted registry, get packages from there and install it. Default registry - https://www.npmjs.com.
3- Writing scripts that can automate some of your workflows.
and much more. 

You can relate it to `pip` if you are coming from python world.

 

Why you need a package manager?
Suppose you are working on an app which requires you to play with Date and Time. Something like times in different zone. Either you can write the logic from scratch or you can use a package like date-fns. 

1- Install date-fns

npm i date-fns 

i stands for install. You can write - `npm install date-fns`


and you can use it like

import { format, formatDistance, formatRelative, subDays } from 'date-fns'

format(new Date(), "'Today is a' iiii")
//=> "Today is a Sunday"

date-fns is very powerful. You can do a lot with it. npm has ton of packages. Head to npmjs.com and find for your use case. 

Some of the popular packages that you might check:

1- Lodash - A JavaScript utility library which makes it easy to work with Array, Functions etc.
2- Chalk - Makes console.log() statement colorful.
3- Nodemon- It's a tool that helps develop node.js based applications by automatically restarting the node application when file changes
4- React, Angular, Express, restify and list goes on. All uses npmjs.com

Discussion

Be the first one to comment!