Skip to content

Instantly share code, notes, and snippets.

@massahud
Last active February 8, 2024 14:30
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.

@gaurav21r
Copy link

npm packages are really old, we are at 3.0+ but site http://nodejs.org/dist/npm/ is only at 1.4.9

@fluffgfx
Copy link

For more up-to-date npm use https://registry.npmjs.org/npm/-/npm-{version}.tgz. Latest version as of this writing is 3.7.3 - so use https://registry.npmjs.org/npm/-/npm-3.7.3.tgz and use 7Zip or whatever to unzip it.

@rahilwazir
Copy link

This didn't worked for me, In case someone is looking for other solution:
https://codyswartz.us/wp/finds/node-js-stand-alone-portable-with-npm

@a-teammate
Copy link

This is only portable as long as you have git in your PATH

if you dont, take a look at this (really portable we assume) solution: https://github.com/inexor-game/platform/tree/master/bin/windows
(which needs an invocation like that: https://github.com/inexor-game/code/blob/master/tool/node_windows_generic_handler.bat )

@jorgeas80
Copy link

@s-h-a-d-o-w
Copy link

This is actually a great guide but the comments may unnecessarily confuse people looking at this.

a) It doesn't matter whether npm is out of date, that's why it says "npm install -g npm". As of npm 3.10.8, updating to that version straight from 1.4.9 works just fine.
b) You don't need any other guide or prepackaged thing.

The only thing I'd change about this guide is using something like the following command for updating npm instead:

npm install npm@latest

Because IMO, using the global flag is against the whole point of creating a portable node/npm "bundle".
(as for "npm@latest" - simply because it seems to be the officially recommended way of doing things)

Also note that setting the PATH is important for using this portable bundle, even if you create/copy it straight to the root of your project. I thought to myself "I can call everything straight from there - what could possibly happen?". But then one of the tools I used tried to launch a sub process in one of the sub directories. And of course, there, all the tools couldn't be found.

@NN---
Copy link

NN--- commented Dec 16, 2016

Download npm + nodejs in one zip https://nodejs.org/dist/v7.2.1/

@PabloEzequiel
Copy link

It works for me!

@GlassGruber
Copy link

  1. Download the last tgz version of npm from http://nodejs.org/dist/npm
  2. Open the tgz file and unpack only the file bin/npm (without extension) directly on the node folder.

Can you tell me why the above? Aren't the .zip and .tgz content exactly the same? As far as I can see they are.

@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 react-scripts@0.9.x 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

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