Skip to content

Instantly share code, notes, and snippets.

@abbotto
Last active October 7, 2016 11:30
Show Gist options
  • Save abbotto/a86a54b3f087fb57911c0c80f3e32a61 to your computer and use it in GitHub Desktop.
Save abbotto/a86a54b3f087fb57911c0c80f3e32a61 to your computer and use it in GitHub Desktop.
NodeJS Environment Setup Tasks
#!/bin/bash
printf "\n-----------------------------------------\n"
printf "N.E.S.T.\n"
printf "NodeJS Environment Setup Tasks"
printf "\n-----------------------------------------\n"
# Requires nvm and nodejs
# Put this in the same folder as "package.json"
# Source the following script to make nvm() available
. ~/.nvm/nvm.sh
printf "\nGetting the correct NodeJS version for the current project...\n"
NODE_VERSION=$(node -p -e "require('./package.json').engines.node")
printf "v$NODE_VERSION is required."
printf "\n\nSwitching to v$NODE_VERSION...\n"
rm -rf node_modules
nvm install $NODE_VERSION
printf "\nInstalling v$NODE_VERSION modules...\n"
npm install
printf "\nNodeJS has been setup for your project.\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment