Skip to content

Instantly share code, notes, and snippets.

@sunderee
Last active August 26, 2023 19:52
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 sunderee/a8d2915b3c55e08a4e9290a359f9f9fb to your computer and use it in GitHub Desktop.
Save sunderee/a8d2915b3c55e08a4e9290a359f9f9fb to your computer and use it in GitHub Desktop.
Node.js scripts for macOS users
#!/usr/bin/env bash
GREEN="\033[0;32m"
BLUE="\033[0;34m"
CLEAR="\033[0m"
echo -e "${GREEN}Listing global NPM packages...${CLEAR}"
npm list -g --depth=0
echo -e "${GREEN}...updating & upgrading global NPM packages...${CLEAR}"
sudo npx npm-check --global --update-all
echo -e "${BLUE}...done!${CLEAR}"
#!/usr/bin/env bash
latest_version=$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')
current_version=$(node --version)
echo "Latest version: ${latest_version}. Current version: ${current_version}"
if [ "$latest_version" = "$current_version" ]; then
echo "You already have the latest Node.js."
echo
else
echo "You do not have the latest version of Node installed"
echo "Use the following command:"
echo " curl "https://nodejs.org/dist/latest/node-"${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}".pkg" > ""$HOME"/Downloads/node-latest.pkg" && sudo installer -store -pkg ""$HOME"/Downloads/node-latest.pkg" -target \"/\""
echo
fi
npm_latest_version=$(npm show npm version)
npm_current_version=$(npm --version)
echo "Latest NPM version: ${npm_latest_version}. Current NPM version: ${npm_current_version}"
if [ "$npm_latest_version" = "$npm_current_version" ]; then
echo "You already have the latest NPM."
else
echo "You do not have the latest NPM"
echo "Use the following command:"
echo " sudo npm instal --global npm@$npm_latest_version"
fi
#!/usr/bin/env bash
NODE_VERSION="v18.13.0"
echo "To install ${NODE_VERSION}, run the following command:"
echo " curl "https://nodejs.org/dist/${NODE_VERSION}/node-"${VERSION:-$(wget -qO- https://nodejs.org/dist/${NODE_VERSION}/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}".pkg" > ""$HOME"/Downloads/${NODE_VERSION}.pkg" && sudo installer -store -pkg ""$HOME"/Downloads/${NODE_VERSION}.pkg" -target \"/\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment