Skip to content

Instantly share code, notes, and snippets.

@r-a-y
Last active September 28, 2023 05:36
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-a-y/ead95fd11a1914657c29 to your computer and use it in GitHub Desktop.
Save r-a-y/ead95fd11a1914657c29 to your computer and use it in GitHub Desktop.
Using node.js / npm with PortableGit

Prologue

I develop on Windows (yeah, I hear your jeers, linux users!), so to use Git, I use Git for Windows.

However, I use Git for Windows (portable version) so I can keep my dev environment centrally located. This is so I can reuse this environment simply by copying my PortableGit directory to a USB drive.

Using a portable set up means you can't use those handy automatic installers to your dev environment. This makes installing other scripts like node.js a little bit more difficult because you have to manually do-it-yourself. No biggie! This is what this guide is for!

Installation

(1) Download the latest version of PortableGit:

https://github.com/git-for-windows/git/releases/

And follow the instructions below to actually make PortableGit save files in a portable location.
https://gist.github.com/r-a-y/da6c3b1b99aafcb3e97e311280aa9434

(2) Installing node.js and npm

Now that you have PortableGit set up, you should have a folder called home/portable in the folder where you extracted PortableGit.

Download the node.js Windows binary:

https://nodejs.org/en/download/current

Extract the node_modules folder, node.exe and npm to a new home/portable/node folder.

(3) Adding node.js to your PATH (for bash users)

Now that you've installed node.js and npm, you still need to let msysgit know about it so you can run node and npm.

Since I use the bundled version of bash that comes with PortableGit, this section is applicable only to bash users. Windows command-line users have to add the PATH using a method similar to this - https://gist.github.com/Anachron/7006751

Create a file called .bashrc in your home/portable folder.

In it, put the following:

# function to easily add a path
# http://superuser.com/a/39995
pathadd() {
  if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
      PATH="${PATH:+"$PATH:"}$1"
  fi
}

# add node directory to PATH
pathadd $HOME/node

Now, run git-bash.bat as usual and type:

npm --version

You should get the npm version number and you should be up and running!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment