In theory a simple subject, but I feel like there is content worth noting as I learn.

Common Package Managers

Package ManagerEcosystemCommandNotes
npmJavascript / Node.jsnpm install package-name
pnpmJavascript / Node.jspnpm install package-nameClassically known for its efficiency and speed
yarnJavascript / Node.jsyarn add package-name
pipPythonpip install package-name
cargoRustcargo install package-name

Node

Overview

  • @ can allow a version to be specified. @latest will grab the latest version.
  • ^ allows any minor version and patch, i.e. 1.X.X and 1.X.X.
  • ~ allows any patch, i.e. 1.2.X and 1.2.X.
  • When starting on an existing project, run npm install to download dependencies from package-lock.json.
  • npm install --save-dev <package> will make a package dev only.
  • npm uninstall
  • npm create turns out to be an alias for npm 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 start
  • npm test
  • npm stop
  • npm restart

Really just an alias for npm init, but