title: Why does running my globally npm linked package simply open the bin file?
body: <p>If I'm developing the npm package <code>foo</code> and I want it to be globally installed as a command-line application, I can do this simply by adding to my package.json:</p>
  
  <pre><code>"bin": {
      "foo": "./bin/foo.js"
  }
  </code></pre>
  
  <p>Somebody who installs my package globally via npm will have the appropriate batch file and shell script added to their global npm prefix directory. However, suppose I want to be able to launch my package from the shell (or, in the case of Windows, the command prompt). I could do this by creating a batch file/shell script somewhere in one of my PATH directories that simply directly runs my package e.g. <code>@node C:\my\package\directory\bin\foo %*</code>.</p>
  
  <p>This is a fairly simple and obvious solution, but I felt that <code>npm link</code> was better suited, as it feels less hacky and is theoretically designed to do this exact thing. I run <code>npm link</code> in my package directory, then test it by running <code>foo</code> from the command line. Rather than executing my script, though, <code>foo.js</code> is actually opened in my default editor. Investigating in the prefix directory, it turns out that the <code>foo.cmd</code> file (the contents of the <code>foo</code> shell script are similar) that npm created contains this:</p>
  
  <pre><code>"%~dp0\node_modules\foo\bin\foo.js"   %*
  </code></pre>
  
  <p>Compare with the batch file created by <code>npm install -g</code>:</p>
  
  <pre><code>@IF EXIST "%~dp0\node.exe" (
    "%~dp0\node.exe"  "%~dp0\node_modules\npm\bin\npm-cli.js" %*
  ) ELSE (
    @SETLOCAL
    @SET PATHEXT=%PATHEXT:;.JS;=;%
    node  "%~dp0\node_modules\npm\bin\npm-cli.js" %*
  )
  </code></pre>
  
  <p>Why does <code>npm link</code> produce script files that launch a package's bin file instead of launching node with the bin file as an argument? How can I fix this behavior?</p>