Skip to content

Instantly share code, notes, and snippets.

@massahud
Last active November 7, 2024 12:45
Show Gist options
  • Save massahud/321a52f153e5d8f571be to your computer and use it in GitHub Desktop.
Save massahud/321a52f153e5d8f571be to your computer and use it in GitHub Desktop.
Portable Node.js and NPM on windows
  1. Get node binary (node.exe) from http://nodejs.org/download/
  2. Create the folder where node will reside and move node.exe to it
  3. Download the last zip version of npm from http://nodejs.org/dist/npm
  4. Unpack the zip inside the node folder
  5. Download the last tgz version of npm from http://nodejs.org/dist/npm
  6. Open the tgz file and unpack only the file bin/npm (without extension) directly on the node folder.
  7. Add the the node folder and the packages/bin folder to PATH
  8. On a command prompt execute npm install -g npm to update npm to the latest version

Now you can use npm and node from windows cmd or from bash shell like Git Bash of msysgit.

@xyberviri
Copy link

Whats up with all the wrong/old out of date info:

For windows download the latest node-X.X.X-win-x64.7z from the nodejs site https://nodejs.org/dist/latest/

go to the folder and run nodevars.bat

next run npm install npm@latest

and.... your done...

you now have nodejs until you logout, then you just go back and run nodevars.bat the next time you need it.

@Ocean-OS
Copy link

It's 2023 - save yourself some time...

Download and run: https://github.com/crazy-max/nodejs-portable/releases/download/2.10.0/nodejs-portable.exe

Node.js Portable 2.10.0
https://github.com/crazy-max/nodejs-portable

# Menu
 1 - Install
 2 - Shell

* Type 'exit' to leave Node.js Portable

'menu' for help>
  • Press [1] and [Enter]
  • Press [Enter] (or first enter Node version you want)
  • Press [Enter] (or 'x64' for 64bit version)
  Version (default 19.4.0):
  Architecture (default x86):

Checking Node.js version 19.4.0... OK!
Downloading https://nodejs.org/dist/v19.4.0/node-v19.4.0-win-x86.zip................... OK!
Extracting node-v19.4.0-win-x86.zip... OK!
Moving nodejs folder... OK!
Creating Node.js configuration... OK!


'menu' for help>
  • Type menu and [Enter]
  • Type [2] and [Enter]
  • Type [Enter]
'menu' for help> menu

# Menu
 1 - Install
 2 - Shell

* Type 'exit' to leave Node.js Portable

'menu' for help> 2

Checking if Node.js installed... OK!
Creating Node.js configuration... OK!
Checking custom paths...
# C:\Program Files (x86)\Git\cmd Warning: Not found...
# D:\another_path Warning: Not found...
# C:\apps\a_relative_path Warning: Not found...
Adding node to PATH... OK!
Setting NODE_PATH... OK!
Creating launch script... OK!

Press Enter to open the shell...

You're done!

node -v

npm -v

What your speedrun time?!

I'm trying to get node.js and npm so I can package an Electron Fiddle app, and Electron still says that node.js and npm aren't found. How can I fix this?

@tno2007
Copy link

tno2007 commented Jul 11, 2023

Hi @Ocean-OS
In your case I do not recommend a portable version of node. It sounds like your Electron is looking for a system-wide installation.

These days its extremely easy to install node (npm is installed automatically along with node).

Assuming you are using Windows, please run PowerShell as an administrator and run these two commands:

  1. Install Chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

After the install is done, close PowerShell, and open it again as an administrator, then...

  1. Install nodejs
choco install nodejs

Just follow the prompts for each step

@PankhuriTripathi
Copy link

@TFWol
Copy link

TFWol commented Apr 29, 2024

That repo is old and abandoned, just do what @xyberviri mentioned:

Whats up with all the wrong/old out of date info:

For windows download the latest node-X.X.X-win-x64.7z from the nodejs site https://nodejs.org/dist/latest/

go to the folder and run nodevars.bat

next run npm install npm@latest

and.... your done...

you now have nodejs until you logout, then you just go back and run nodevars.bat the next time you need it.

It's the official files and simple.

@WillRubin
Copy link

I was hopeful for a bit there. Unfortunately, the method from @xyberviri does NOT create a portable version. While you can extract the archive to a portable location, when you run npm install npm@latest about 2000 files are created in the local users folder. The folder is named "node_modules" and contains a "npm" folder with the bulk of the files.

@xyberviri
Copy link

xyberviri commented Apr 30, 2024

@WillRubin Oh your right i didnt really notice that because my requirement were run and then delete off of a windows server with out leaving stuff configured, I'm assuming this is for a thumb drive so you can try the following:

Set the thumb drive letter to something that will NOT change between systems like P otherwise stuff breaks

extract the zip files to that drive in the location you want node.js like before im going to assume P:\node-v22.0.0-win-x64\

edit the 4th line of nodevars.bat from set "PATH=%APPDATA%\npm;%~dp0;%PATH%" to set "PATH=%~dp0;%PATH%"

then open a new command prompt and type cd /d P:\node-v22.0.0-win-x64\

then npm install npm@latest that should throw everything into P:\node-v22.0.0-win-x64\ i have zero clue what the repercussions of doing this are but stuff seems to work.

when you open a command prompt and type P:\node-v22.0.0-win-x64\nodevars.bat it should add P:\node-v22.0.0-win-x64\ to your systems %PATH% for that command prompt session.

if stuff breaks try installing npm in a different location it just uses whatever folder you are in unless you use -g in which case it uses %appdata% you can override this with --prefix ./ but that location has to be in your path for stuff to work

@jeanniton-mnr
Copy link

It's 2023 - save yourself some time...

Download and run: https://github.com/crazy-max/nodejs-portable/releases/download/2.10.0/nodejs-portable.exe

Node.js Portable 2.10.0
https://github.com/crazy-max/nodejs-portable

# Menu
 1 - Install
 2 - Shell

* Type 'exit' to leave Node.js Portable

'menu' for help>
  • Press [1] and [Enter]
  • Press [Enter] (or first enter Node version you want)
  • Press [Enter] (or 'x64' for 64bit version)
  Version (default 19.4.0):
  Architecture (default x86):

Checking Node.js version 19.4.0... OK!
Downloading https://nodejs.org/dist/v19.4.0/node-v19.4.0-win-x86.zip................... OK!
Extracting node-v19.4.0-win-x86.zip... OK!
Moving nodejs folder... OK!
Creating Node.js configuration... OK!


'menu' for help>
  • Type menu and [Enter]
  • Type [2] and [Enter]
  • Type [Enter]
'menu' for help> menu

# Menu
 1 - Install
 2 - Shell

* Type 'exit' to leave Node.js Portable

'menu' for help> 2

Checking if Node.js installed... OK!
Creating Node.js configuration... OK!
Checking custom paths...
# C:\Program Files (x86)\Git\cmd Warning: Not found...
# D:\another_path Warning: Not found...
# C:\apps\a_relative_path Warning: Not found...
Adding node to PATH... OK!
Setting NODE_PATH... OK!
Creating launch script... OK!

Press Enter to open the shell...

You're done!

node -v

npm -v

What your speedrun time?!

Your solution has worked for me.

Thank you!

@FahadBinHussain
Copy link

FahadBinHussain commented Oct 8, 2024

2024 updated guide created by me - https://rentry.co/node-portable

Thanks to @progmars

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