0

I am trying to create a command-line utility. But, npm install (no -g) does not link the executable.

My expectation is that npm install would install my executable locally.

My package.json looks like:

{ "name": "test-bin", "version": "0.1.0", "description": "Test bin", "bin": "./bin/test-bin.js", "main": "./index.js", "author": "", "license": "ISC", "repository": { "type": "git", "url": "file:///tmp/test-bin.git" } } 

index.js is:

module.exports = function() { console.log('invoked') } 

bin/test-bin.js is:

require('../')() 

If I run npm install, node_modules is created, but not .bin

However, if create another project elsewhere that uses the first as a dependency:

{ "name": "test-test-bin", "version": "0.1.0", "description": "Test test bin", "author": "", "license": "ISC", "repository": { "type": "git", "url": "file:///tmp/test-test-bin.git" }, "dependencies": { "test-bin": "file:///Users/you/somewhere/test-bin" } } 

then npm install links the executable in that project:

node_modules/.bin/test-bin 

The npm documentation says, about "bin":

To use this, supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.

Is it as designed, or am I missing something?

1 Answer 1

1

Running npm install inside a package folder will install its dependencies, but it doesn't install any binaries that the package itself declares (you could argue what the point of that would be).

That only happens when the package is installed as a package (using npm install package-name or as a dependency for other packages).

Sign up to request clarification or add additional context in comments.

3 Comments

That is what I am observing. It seems to directly contradict what the documentation says though. So, is it a bug, or am I misinterpreting the documentation, or maybe leaving out something in the process that I need to do?
Oh, I see how the documentation could mean that now. By local install, they mean local install of the package that has the executable as a dependency.
You're right: you have local (npm install package-name) and global (npm install package-name -g) installs, with the difference being where the installed package ends up (in ./node_modules for local, of the system-wide node_modules for global). Running just npm install doesn't really have a name like that AFAIK, but what is does is installing dependencies.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.