I would like to publish a NPM package with a CLI utility in it. In the package.json
, I have the following line:
"bin": "index.js"
When I install the package on Windows, a batch file is being generated under Roamingnpm
, it’s called mypackage.cmd
, and the final line goes:
"%dp0%node_modulesmypackageindex.js" %*
It’s not executing the script under Node.js, it’s executing the JavaScript file as is – not the desired result. On my dev box, for one, the default association for .js
files is Visual Studio Code, not Node. Looking at other modules’ generated batch scripts, I see that the final line is different:
"%_prog%" "%dp0%node_modulesanotherpackagebinsomescript.js" %*
where _prog
is initialized to the Node executable.
I want the bin
script to execute explicitly under Node. What is missing in my package (presumably in package.json
)?