Skip to content

Instantly share code, notes, and snippets.

@blizzz
Last active September 27, 2022 21:38
Show Gist options
  • Save blizzz/0bb7e2e617742dcc5cbaf7b7216062f4 to your computer and use it in GitHub Desktop.
Save blizzz/0bb7e2e617742dcc5cbaf7b7216062f4 to your computer and use it in GitHub Desktop.
Execute a command with the node and npm version as required in package.json (on arch)
#!/bin/env bash
# requires nvm installed from AUR (i.e. only tested on Arch), and also jq
# run from the project directory like: runWithNodeAndNpm.sh make dev-setup
# the package.json is taken from the current working directory
NODE_MAJOR_VERSION=$(cat package.json | jq .engines.node | grep -oE '[0-9]*' | head -1)
NPM_MAJOR_VERSION=$(cat package.json | jq .engines.npm | grep -oE '[0-9]*' | head -1)
source /usr/share/nvm/init-nvm.sh
nvm install ${NODE_MAJOR_VERSION} && \
npm install -g npm@${NPM_MAJOR_VERSION} && \
${@}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment