joyent/node — Issue #2406: Bundle npm as an executable in Windows installer
Author: matt-hickford
Created: 2011-12-22 23:52:09+00:00
State: open

Hi. It's great progress that Node now has a [Windows installer](http://blog.nodejs.org/2011/12/15/growing-up/) and delightful that the installer bundles the package manager npm. Note that a batch file wrapper `npm.cmd` is installed beside the node executable. Assuming the Node folder is in the path, a user at the Windows command prompt can use the package manager with the command `npm`. However if the user is using Bash or any other unix shell (as distributed with MSYS or cygwin) they can't run `npm` because their shell can't execute batch files.

The solution is to [additionally] wrap npm in Windows executable `npm.exe`. This is the convention—if I browse to `C:\Ruby193\bin` it has both `gem.bat` and `gem` (a Windows executable), `rake.bat` and `rake`.

For reference, the batch file `npm.cmd` looks like this

:: Created by npm, please don't edit manually.
@IF EXIST "%~dp0"\"node.exe" (
"%~dp0"\"node.exe" "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
) ELSE (
node "%~dp0\.\node_modules\npm\bin\npm-cli.js" %*
)

How can we make a Windows executable that does the same thing?