I'm trying to create a node.js command line utility and having an issue with wrapper that npm generates. My super-simple demo is a package.json file:
{
"name": "demo-cli",
"version": "0.0.1",
"bin": { "demo": "bin/demo-cli.js" }
}
And the demo-cli.js file:
console.log('DEMO WORKED');
The issue is when I install the module using npm install -g
while in the project directory the wrapper it generates does not call node with the file as the parameter. This is the generated contents of demo.cmd:
:: Created by npm, please don't edit manually.
"%~dp0\.\node_modules\demo-cli\bin\demo-cli.js" %*
The unix version has the same issue. Looking at another globally installed CLI I can see that node is being tested for and called as expected.
:: Created by npm, please don't edit manually.
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\.\node_modules\mocha\bin\mocha" %*
) ELSE (
node "%~dp0\.\node_modules\mocha\bin\mocha" %*
)
What is the secret sauce needed for npm to generate the proper script file? I've tried everything I could find or think of, including removing the .js extension, preferring global, specifying the node version...no luck.
I'm using node v0.6.18 and npm v1.1.21 on Windows 7 x64.
Try putting
#!/usr/bin/env node
At the top of your demo-cli.js
file.
On windows, npm
looks for this shebang line when creating the .cmd
wrapper. See cmd-shim.js in the npm
source for more info.