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/binfor global installs, or./node_modules/.binfor 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.
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" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With