An introduction to NPM - Node Package Manager
What is Node.js
Traditionally, JavaScript was used just to do web-browser'ish (Front-end tasks) things like opening a modal window, opening and closing a toggle menu etc.
For Server'ish or Computer'ish tasks (Back-end things) like Accessing file system, interacting with the database, sending automated emails etc languages like PHP, Python etc were used.
Node.js lets us do almost any back-end tasks (Server'ish or Computer'ish things) with JavaScript.
Node.js is an open source, a cross-platform runtime environment for developing server-side and networking applications. Node.js applications are written in JavaScript and can be run within the Node.js runtime on OS X, Microsoft Windows, and Linux.
Node.js is a platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
So, Node.js is used in two major ways:
1. It is installed on a server and it takes and processes all server requests.
2. It is installed on our personal computer and used as a development tool. Node.js in our PC becomes our personal assistant Robot and can be used to automate all sorts of development tasks.
In our Personal Computer, we can make node do all sorts of automation. And the best news is that we do not have to write much code to do create all these automatons. We can leverage code that other super intelligent people have already written and shared with the world. And this is exactly where NPM comes into play.
NPM Stands for N ode P ackage M anager.
What is NPM? What is package management in general?
If there are a few tasks that we need to automate using node.js, most of the times, we don't need to write much code, we can just go to NPM and get the package that has all the code that we need.
NPM is a Centralized place where Node developers share their code with the world.
In very simple words, a package is a list of codes that we need in our project. We hand over that list to our personal robot (Node.js) and it takes care of downloading/updating all the code that we need.
What Type of packages do we hope to find on NPM?
1. Node packages: Packages that help us do things in Node.js. There is a package for almost any server tasks or automation that we need to do with node. Eg. Gulp, Request, Grunt etc.
2. Other things: These packages have nothing to do with Node.js. Eg. jQuery, Bootstrap, Normalize.css etc.
NPM is a lot bigger than just Node.js. It is a one-stop-shop for any code that we need.
Few Simple Examples:
In order to download jQuery files to our project, we just have to navigate to our project directory and perform two simple steps our command prompt or terminal:
Step 1 (optional): Creating a code list for our Robot. This file (package.json) keeps track of all the packages that our project uses.
npm init
Step 2: Adding Jquery to list and downloading it
npm install jquery
As easy as that!!
Sr. Drupal Developer at Axelerant
4yVery well explained !!