Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienjoly/decbe059f846de8b2bf14ecb441c2529 to your computer and use it in GitHub Desktop.
Save adrienjoly/decbe059f846de8b2bf14ecb441c2529 to your computer and use it in GitHub Desktop.
Run a node.js CLI from a github repository, using a specific version of Node.js installed locally with NVM. Addresses `nvm: command not found` error, when `nvm` is invoked from a bash script.
#!/usr/bin/env bash
# Run index.js (or the script specified in package.json's "bin" entry)
# from https://github.com/adrienjoly/notion-backup,
# with the version of 18 of Node.js, installed locally with NVM.
NODE_VERSION=18 ~/.nvm/nvm-exec npx --yes github:adrienjoly/notion-backup
# Why you may need this?
# - If, like me, you have not setup a default version of node.js, on NVM.
# - If you don't want to (or can't) include a `.nvmrc` file.
# - And because `nvm use` does not work from a script file like this one.
# Note: the project's `index.js` file must start with the following header:
# !/usr/bin/env node
➜ ~ nvm current
❌ none
➜ ~ node --version
❌ zsh: command not found: node
➜ ~ NODE_VERSION=18 ~/.nvm/nvm-exec node --version
✅ v18.15.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment