In theory a simple subject, but I feel like there is content worth noting as I learn.
Common Package Managers
| Package Manager | Ecosystem | Command | Notes |
|---|---|---|---|
| apt | Linux | apt install package-name | System wide software, not really for libraries |
| npm | Javascript / Node.js | npm install package-name | |
| pnpm | Javascript / Node.js | pnpm install package-name | Classically known for its efficiency and speed |
| yarn | Javascript / Node.js | yarn add package-name | |
| pip | Python | pip install package-name | |
| cargo | Rust | cargo install package-name |
Node
Overview
@can allow a version to be specified.@latestwill grab the latest version.^allows any minor version and patch, i.e.1.X.Xand1.X.X.~allows any patch, i.e.1.2.Xand1.2.X.- When starting on an existing project, run
npm installto download dependencies frompackage-lock.json. npm install --save-dev <package>will make a package dev only.npm uninstallnpm createturns out to be an alias fornpm init. In essence, it is a short way to use a tool (such as vite) to set up and initialize a new project quickly. Example:npm create vite@latest my-react-app -- --template react.
What is npx?
A tool for executing node packages. Not a package manager, however it does run one-time-use packages (or project specific CLI tools) without installing them. Can technically be done with npm exec.
package.json
A human readable manifest of the project dependencies, along with some configuration for metadata and scripts. Scripts define commands that are run when calling npm run <script> e.g. npm run build.
package-lock.json
Automatically generated when running npm install. It specifies installed package versions to ensure consistency across different environments. This file should be committed.
npm start
Turns out there are a few commands that are shorthands for frequent operations like npm run start. In fact, if no start script is defined in package.json, it will run node server.js by default. The list is as follows:
npm startnpm testnpm stopnpm restart
Really just an alias for npm init, but