npm is widely used by nodejs, angular, react, vuejs frameworks, you can create your own package and publish the package to the marketplace.
it is very helpful to share the code, plugin with other developers and the open-source community. npm has boosted the open source community to a new level.
To use the npm, you need to install the nodejs, npm is in-built with nodejs.
You can download the nodejs from the official site nodejs.org,
After downloading, please install it.
- For windows
Install it in the c drive, and copy the installed location path
C:\Program Files\nodejsand add it in your enviorement variables
After installing the nodejs, you can verify the installation by running the
npm --version command from your command runner.
package.json file is used to maintain the all npm package with the version. this file contains all the npm packages you installed.
npm init command to generate the
package.json file while running this command it will ask some details like -
package name: Name of the package you want to add like demo-app
version: version by default 1.0.0
description: add description
entry point: when you run
npm start, the provided entry point will run, you can add index.js or leave blank it
test command: Any script you want to use for testing
git repo path: You can provide your GitHub repo URL
keywords: For searching and SEO purpose
author: Add the name of the author
licence: Add like MIT or ISC
You can get the npm package you want to install from the NpmJS
You can install the package globally and locally
- a. Globally
To install any package you need to add
-g prefix like
npm i expressjs -g : it will install the expressjs globally, you don't need to install it for your projects individually.
The package will be accessibly globally.
- b. Locally
npm i expressjs : it will install the expressjs locally, the package will be only accessible to your local project.
Below is the list of all npm commands
npm init: to generate the package.json file
npm install: to install all packages of the
npm i -g: install the package globally
npm start: It will execute the entry point script you added in the
npm install npm@latest -g: Upgrade the npm package to the latest version
npm outdated: list of all out date packages
npm list -g: list of all global npm packages
npm uninstall "package name": it will uninstall the package
npm publish: This is used to publish the package at npmjs