Skip to content

Instantly share code, notes, and snippets.

@dsculptor
Created May 19, 2022 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsculptor/aab74ce813091a6f3766d3c71a395108 to your computer and use it in GitHub Desktop.
Save dsculptor/aab74ce813091a6f3766d3c71a395108 to your computer and use it in GitHub Desktop.

Quick Reference to manage npm, nodejs

1. Install n & nodejs-v17.latest

Best Method: use n. Its lovely & bootstraps itself as an npm pkg without npm.

function ubuntu-install-nodejs-17() {
  echo "Installing nodejs via n in /usr/local/bin with /usr/local/n as cache folder"
  echo "For more details see: https://github.com/tj/n"
  
  echo "--- Yes this is needed ---"
  sudo mkdir -p /usr/local/n /usr/local/node_modules /usr/local/include /usr/local/share
  sudo chown -R $(whoami) /usr/local/n
  sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

  pushd /tmp
  if ! command -v n &>/dev/null; then
    echo "n is not installed. Installing any basic version of n..."
    curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n
  else
    echo "n is already installed..."
  fi

  echo "Making sure node v17 is installed"
  bash n 17
  
  echo "Installing a full version of n based on node-v17"
  npm install -g n
  popd
}

ubuntu-install-nodejs-17

2. How to update pkgs

via npm

npm [-g] list --depth 0   # see whats there?
npm outdated   # See list of outdated pkgs
npm update     # Update minor versions. ex: 3.2.3 -> 3.5.0 

via node-check-updates pkg:

## More details: https://www.npmjs.com/package/npm-check-updates
ncu -u -t minor  # Change package.json with minor version updates
ncu -u           # Change package.json with major version updates [ ☠️ DANGER ☠️ ]

Run the updates

## Run the updates
npm install && npm ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment