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.

@ProductiveAsparagus56
Copy link

Found a tutorial here: https://www.youtube.com/watch?v=N8cFnUruUEo (TimeStamps in description)

@CodeZeno
Copy link

In step 7 what packages/bin folder is being refered to? After following steps I have:

  • node_modules (folder)
  • node.exe (file)
  • npm (file)
  • npm.cmd (file)

@thdoan
Copy link

thdoan commented May 23, 2018

To improve portability, set the following (change path to wherever you installed it):

:: Set the location of globally installed npm modules
npm config set prefix /dev/nodejs --global

:: Set the location of the npm cache
npm config set cache /dev/nodejs/npm-cache --global

:: Uncomment if 'npm install' is not working for a module in Windows
::npm config set python /path/to/python/python.exe --global
::npm config set msvs_version 2010 --global

@tik9
Copy link

tik9 commented Mar 6, 2021

In step 7 what packages/bin folder is being refered to? After following steps I have:

  • node_modules (folder)
  • node.exe (file)
  • npm (file)
  • npm.cmd (file)

Same to me, do not know what you mean with packages/bin.

@yuis-ice
Copy link

yuis-ice commented Feb 2, 2022

Great. Thank you.

@progmars
Copy link

progmars commented Nov 14, 2022

These days you just go to https://nodejs.org/en/download/ and download the binary zip - it has the proper npm version.

Instead of modifying PATH globally, there should be a way to modify it for your node session only.

For example, I have been using the following approach to run custom Java and Python environments:

@echo off
setlocal EnableExtensions DisableDelayedExpansion

set JAVA_HOME=C:\path\to\my\custom\java\portable\folder

echo Now you can run your Java commands in this console!

rem Keeping it open for running Java commands
cmd /k

I think it should be possible to use a similar approach for nodejs, modifying PATH for the current session. And, of course, modifying the global paths also to prevent npm from polluting your OS with cached library files.

@tno2007
Copy link

tno2007 commented Jan 23, 2023

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?!

@abrakhim
Copy link

abrakhim commented Feb 7, 2023

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?!

...dude, this repo stinks of virus, says me computer... i would recommend following progmars comment or the original one
( This may be just McAffee being paranoid though, Bitdefender and F-Secure think it clean)
https://www.virustotal.com/gui/file/fb951d3186b65a831453a187f6ee313af91de289c43c246f0e25a62657c919c8

Considering that crazyMax has bothered to reply in the community part of the VirusTotal-Scan, i would wager on false positive ;-)

@tno2007
Copy link

tno2007 commented Feb 7, 2023

...dude, this repo stinks of virus, says me computer... i would recommend following progmars comment or the original one

Would you mind posting your antivirus results here?

I'm asking, because I use this daily and if this was a virus, it would not even be allowed on github

@abrakhim
Copy link

abrakhim commented Feb 7, 2023

Sure, added them in my original post.

@loredonrj
Copy link

Sure, added them in my original post.

Thank you so much dude!! I've been struggling with installing a node.js portable version for weeks!!! It works like a charm.

@massahud
Copy link
Author

I haven't seen that people are using and commenting this old gist :)
I hadn't used windows for some time, so I can't help if the steps are not working anymore.

@loredonrj
Copy link

I haven't seen that people are using and commenting this old gist :) I hadn't used windows for some time, so I can't help if the steps are not working anymore.

It still works fine 👍🏿

@fritol
Copy link

fritol commented May 15, 2023

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?!

hey am also from 2023 so
thank you, chief! works like a charm

@reactstudent
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?!

hey am also from 2023 so thank you, chief! works like a charm

I'm new to software and trying to learn on a USB device connected to a laptop user account without administrative access. I'm getting this error.

"Error: double-loading config "F:\Documents\NodePortable\app\etc\npmrc" as "global", previously loaded as "user"
at #loadObject (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:561:13)
at F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:600:31
at async #loadFile (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:599:5)
at async Config.load (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:287:5)
at async #load (F:\Documents\NodePortable\app\node_modules\npm\lib\npm.js:227:5)
at async module.exports (F:\Documents\NodePortable\app\node_modules\npm\lib\cli.js:68:5)
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

Error: double-loading config "F:\Documents\NodePortable\app\etc\npmrc" as "global", previously loaded as "user"
at #loadObject (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:561:13)
at F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:600:31
at async #loadFile (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:599:5)
at async Config.load (F:\Documents\NodePortable\app\node_modules\npm\node_modules@npmcli\config\lib\index.js:287:5)
at async #load (F:\Documents\NodePortable\app\node_modules\npm\lib\npm.js:227:5)
at async module.exports (F:\Documents\NodePortable\app\node_modules\npm\lib\cli.js:68:5)

Aborting installation.
npm install --no-audit --save --save-exact --loglevel error react react-dom [email protected] has failed.

Deleting generated file... package.json
Deleting todoapp/ from F:\Documents\NodePortable\work"

Could you help please?

@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