|
| 1 | +# Software Package Manager |
| 2 | + |
| 3 | +A package manager or package-management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for a computer in a consistent manner. A package manager deals with packages, distributions of software and data in archive files. |
| 4 | + |
| 5 | +A package manager is a programming language’s tool to create project environments and easily import external dependencies. You don’t have to reinvent the wheel and are able to make the most of the tools at your disposal. When working on a project or library, you may “package” your project and publish it for others. |
| 6 | + |
| 7 | +You can usually specify dependencies, a package name, author, tags/keywords and version number. |
| 8 | + |
| 9 | +# What is NPM? |
| 10 | + |
| 11 | +NPM stands for the Node Package Manager. |
| 12 | + |
| 13 | +npm is the package manager for JavaScript. It is the world’s largest software repository. npm hosts extremely popular packages like jQuery, Bootstrap, React, Angular etc. Linking your GitHub repository with npm also allows you to create and share your own projects. As the npm online repository is so large and diverse, JavaScript front-end and Node.js backend developers make use of npm as the packages can be used in either environment. |
| 14 | + |
| 15 | +NPM is bundled with Node.js Runtime. It is Node.js Default Package Manager. In other words, when you install Node.js, NPM gets installed. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +Every NPM package will be installed in the `node_module` folder. Running `npm install <module>` installs the latest package version available in the NPM registry. |
| 20 | + |
| 21 | +**Installing a Specific Package Version** |
| 22 | + |
| 23 | +``` |
| 24 | +npm install lodash@4.17.19 ## install lodash version 4.17.19 |
| 25 | +``` |
| 26 | + |
| 27 | +**Uninstalling a Local Package** |
| 28 | + |
| 29 | +``` |
| 30 | +npm uninstall <package-name> |
| 31 | +``` |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +**DevDependencies** |
| 36 | + |
| 37 | +DevDependencies are the packages that are not required by the app to run. These packages are used for development purposes such as testing, local server speeding for development purposes, transpiring code, etc. |
| 38 | + |
| 39 | +``` |
| 40 | +npm install nodemon --save-dev ## install a dev package to our dependencies |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +## Package.json Dependencies Management |
| 46 | + |
| 47 | +The main aim of using package.json is to define your application’s dependencies. |
| 48 | + |
| 49 | +## Package-lock.json |
| 50 | + |
| 51 | +In version 5, npm introduced the package-lock.json file. |
| 52 | + |
| 53 | +The goal of package-lock.json file is to keep track of the exact version of every package that is installed so that a product is 100% reproducible in the same way even if packages are updated by their maintainers. |
| 54 | + |
| 55 | +This file “locks down” your dependency versions. That way whenever someone else runs yarn install or npm install, they’ll receive the exact dependencies versions listed out in the lock file. This ensures that your team has the identical package versions as you do. It also helps prevent bugs that can appear due to the introduction of updated, untested package versions. |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +When a package is installed, it is saved with a caret (^) before the version number in the dependencies scaffold. The caret tells NPM always install the highest version available for this package that matches the major version available in the project’s dependencies. |
| 60 | + |
| 61 | +But if the package-lock.json file is available in that project, NPM will match the version specified in the lock file. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +# What is Yarn? |
| 66 | + |
| 67 | +Yarn is a JavaScript package manager created by Facebook. Yarn stands for Yet Another Resource Negotiator. It provides similar functionalities as NPM. It is an alternative to NPM when installing, uninstalling, and managing package dependencies from the NPM registry or GitHub repositories. |
| 68 | + |
| 69 | +# NPM vs Yarn |
| 70 | + |
| 71 | +One of the main difference between NPM and Yarn is how they handle the package installation process. Yarn installs packages in parallel. Yarn is optimized to fetch and install multiple packages simultaneously. |
| 72 | + |
| 73 | +When you install a package, these two package managers save offline cache. You can then install a package you installed before from the memory cache even when you are offline. Yarn has a well-managed offline cache. |
| 74 | + |
| 75 | +# NPM vs Yarn new updates |
| 76 | + |
| 77 | +Yarn and NPM are continually updating to improve on their current features, as well as adding new features such as NPX and PnP. |
| 78 | + |
| 79 | +**NPX** |
| 80 | + |
| 81 | +NPX stands for Node Package Executor. It is a new addition to NPM version 5.2.0 or higher. NPX helps you to execute one-off commands. With NPX, you can execute packages from the NPM registry without installing them to your project dependencies. |
| 82 | + |
| 83 | +There are more features that you can benefit from using NPX. Check this guide to learn more about NPX. |
| 84 | + |
| 85 | +for more information, [read here](https://www.section.io/engineering-education/npm-vs-yarn-which-one-to-choose/) |
0 commit comments