Table of Content
Assume you have portable git/msys, you can find details in portabledevops in github.
There are two parts for node.js
- node, Node.js interpreter
- npm, node package manager
I would like to carry node.js in usb driver, found the npm default configuration is too close to windows environment:
prefix = "C:\\Users\\username\\AppData\\Roaming\\npm" cache = "C:\\Users\\username\\AppData\\Roaming\\npm-cache tmp = "C:\\Users\\username\\AppData\\Local\\Temp"
the good thing is you can change them to portable node.js folder in npm global setting, for example:
npm config set prefix=nodejs/.node_modules_global npm config set cache=nodejs/npm-cache npm config set tmp=/home/username/AppData/Local/Temp
sample of portable node.js setting in portabledevops.sh
You can check out portabledevops.sh in portabledevops , and place it in your git/msys /etc/profile.d/ folder, it will be sourced each time when launch bash by "bash –login -i" .
# portable nodejs export PATH=$PORTABLEPATH/nodejs:$PATH if [ ! -d $PORTABLEPATH/nodejs/.node_modules_global ]; then echo "First time to create npm modules global: $PORTABLEPATH/nodejs/.node_modules_global" mkdir -p $PORTABLEPATH/nodejs/.node_modules_global fi $PORTABLEPATH/nodejs/npm config set prefix=$PORTABLEPATH/nodejs/.node_modules_global if [ ! -d $PORTABLEPATH/nodejs/npm-cache ]; then echo "First time to create npm-cache: $PORTABLEPATH/nodejs/npm-cache" mkdir -p $PORTABLEPATH/nodejs/npm-cache fi $PORTABLEPATH/nodejs/npm config set cache=$PORTABLEPATH/nodejs/npm-cache if [ ! -d $PORTABLEPATH/home/$USERNAME/AppData/Local/Temp ]; then echo "First time to create tmp: $PORTABLEPATH/home/$USERNAME/AppData/Local/Temp" mkdir -p $PORTABLEPATH/home/$USERNAME/AppData/Local/Temp fi $PORTABLEPATH/nodejs/npm config set tmp=$PORTABLEPATH/home/$USERNAME/AppData/Local/Temp export PATH=$PORTABLEPATH/nodejs/.node_modules_global:$PATH
verify portable node.js
$ which -a node /L/portabledevops/nodejs/node $ node -v v6.3.1 $ which -a npm /L/portabledevops/nodejs/npm $ npm -v 3.10.3 $ npm config ls user-agent = "npm/3.10.3 node/v6.3.1 win32 x64" cache = "L:\\portabledevops\\nodejs\\npm-cache" prefix = "L:\\portabledevops\\nodejs\\.node_modules_global" tmp = "L:\\portabledevops\\home\\username\\AppData\\Local\\Temp" $ npm list -g --depth=0 L:\portabledevops\nodejs\.node_modules_global `-- gitbook-cli@2.3.0
Enjoy portable node.js !