NPM stands for Node Package manager. It’s a package manager for JavaScript projects. NPM is trusted by more than 11 million developers worldwide and it is is committed to making JavaScript development elegant, productive, and safe. Here I am sharing the most important npm interview questions.

What is NPM?

NPM stands for Node Package Manager. NPM is a package manager for JavaScript programming language maintained by npm, Inc. It is the default package manager for the JavaScript runtime environment Node.js. NPM is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.

  • npm downloads automatically as soon as you install node.js
  • npm -v command we can use to check the npm version.
  • npm use to manage dependencies in your project, so using npm install command we can install any package as local dependency or global dependency.

Difference between NPM and NPX

NPMNPX
If you wish to run package through npm then you have to specify that package in your package.json and install it locally.NPX is a tool that use to install package.
Npm is a tool that useto install packages.Npx is a tool that use to execute packages.
For Examle:
To use ‘create-react-app’ in npm the commands are
‘npm install create-react-app’ then ‘create-react-app myApp’ (Installation required)
For Examples:
In npx you can create a react app without installing the packages:
‘npx create-react-app myApp’
This command is required in every app’s life cycle only once.

Difference between npm i and npm ci

npm i:

  • npm i (or npm install) is used to install all dependencies or devDependencies from a package.json file.
  • syntax: npm i “package-name”
  • npm install can update your package-lock.json when there are changes such as when you install a new dependency.
  • Use npm install to install new dependencies, or to update existing dependencies (e.g. going from version 1 to version 2)

npm ci:

  • ci stands for continuous integration and npm ci is used to install all exact version dependencies or devDependencies from a package.json file.
  • Syntax: npm ci
  • Unlike npm install, npm ci will never modify your package-lock.json
  • Use npm ci when running in continuous integration, or if you want to install dependencies without modifying the package-lock.json

Difference between package.json and package-lock.json

package.json:

  • It contains basic information about the project.
  • It is mandatory for every project.
  • It records important metadata about the project.
  • It contains information such as name, description, author, script, and dependencies.

package-lock.json:

  • It describes the exact tree that was generated to allow subsequent installs to have the identical tree.
  • It is automatically generated for those operations where npm modifies either node_modules tree or package.json
  • It allows future devs to install the same dependencies in the project.
  • It contains the name, dependencies , and locked version of the project.

How to solve npm error npm ERR! code ELIFECYCLE?

This is very common error that we usually get whenever we perform some operations like npm install. There are some steps that can be followed to solve this issue:

Clean npm cache:

npm cache clean-force

Delete node_modules folder.

Delete package-lock.json file

Install the packages again

npm install

Conclusion: Understanding npm is quiet important as each project has dependencies which we handle using package manager and npm is one of the most popular package manager.

Also Read:

Categorized in: