NPM stands for Node Package Manager. It is:
- the default package manager that comes with the Node.js
- a command-line utility works with said repository to manage packages.
In npm versions 3 and earlier, many developers faced a dependency versions problem where the app broke when moving a project from one machine to another. Npm did have a shrinkwrap command in an earlier version that created a lock file. The problem with this was that the file could not be generated automatically, you had to always update it yourself. To fix this problem, yarn automatically installs (updates) a yarn.lock file that contains the exact same version of the dependency that should be installed on every device. After yarn, Npm 5 introduced the package-lock.json file to replace npm-shrinkwrap.
NPM installs packages one by one, waiting for the first package to be installed before beginning the next. Yarn, by contrast, speeds up the process by installing multiple packages at the same time. Additionally, yarn stores the package to your disk such that for the next installation, the package is immediately used instead of waiting for an HTTP request to get it.
- After creating a React app by using the following command:
npx create-react-app my-app-name
We can create a package.json file by using:
npm init //or yarn init
- The following commands are used for adding/updating/deleting packages
//using npm npm install <package..> npm upgrade <package..> npm uninstall <package..> //using yarn yarn add <package..> yarn upgrade <package..> yarn remove <package..>