Create a global directory for node modules installed with npm

This commit is contained in:
Bob Mottram 2018-03-30 14:07:33 +01:00
parent 8094acfdf1
commit 88b9907f6f
1 changed files with 17 additions and 0 deletions

View File

@ -173,6 +173,8 @@ EOF
fi
rm "$rootdir/usr/bin/test_nodejs_install"
NODE_UPGRADE=
nodejs_setup_global_modules
}
function nodejs_upgrade {
@ -201,6 +203,21 @@ function nodejs_upgrade {
npm update -g
}
function nodejs_setup_global_modules {
if [ ! -d /root/.npm-global ]; then
mkdir /root/.npm-global
fi
npm config set prefix '/root/.npm-global'
export PATH=/root/.npm-global/bin:$PATH
if ! grep -q "PATH=/root/.npm-global/bin" /root/.bashrc; then
echo "PATH=/root/.npm-global/bin:\$PATH" >> /root/.bashrc
fi
if ! grep -q "NPM_CONFIG_PREFIX=" /root/.bashrc; then
echo "export NPM_CONFIG_PREFIX=/root/.npm-global" >> /root/.bashrc
fi
export NPM_CONFIG_PREFIX=/root/.npm-global
}
function remove_nodejs {
if [ ! "$1" ]; then
return