From 88b9907f6f3bc3b58013c29ec7b468dc72c175d7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 30 Mar 2018 14:07:33 +0100 Subject: [PATCH] Create a global directory for node modules installed with npm --- src/freedombone-utils-nodejs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/freedombone-utils-nodejs b/src/freedombone-utils-nodejs index a557cfff..3068b2bc 100755 --- a/src/freedombone-utils-nodejs +++ b/src/freedombone-utils-nodejs @@ -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