Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local npm install doesn't create symlink to "bin" executables

If I create a minimal package.json file:

{
  "name": "cli-test",
  "version": "1.0.0",
  "bin": "index.js",
  "main": "index.js"
}

and an index.js file:

#!/usr/bin/env node
console.log("Hello")

and run npm install, why doesn't npm create a ./node_modules/.bin/cli-test symlink to my index.js file? The package.json documentation says this on "bin":

On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin for local installs.

If I do npm install -g, a symlink is created, but I don't want a global install. I'm using node 6.10.3 and npm 3.10.10. Also tried with npm 5.0.4.

like image 663
danmichaelo Avatar asked Jun 29 '17 17:06

danmichaelo


1 Answers

Running npm install inside a package directory (which is what you're doing) only installs a package's dependencies, not the package itself:

npm install (in package directory, no arguments):

Install the dependencies in the local node_modules folder.

(from npm help install)

The documentation that you're quoting refers to the package itself being installed.

I typically put executable scripts in ./bin of a package directory, so I can execute them directly, and refer to them from package.json:

"bin" : { "my-cool-cli" : "./bin/my-cool-cli" }
like image 78
robertklep Avatar answered Nov 11 '22 06:11

robertklep