I am creating a "hello world" npm module that I will want to share on npmjs for future use. Once installed, I would like the module to display "hello world" if the user types in "snippet" as a command. This is what my package.json looks like:
{
"name": "test-hello-world",
"version": "0.0.1",
"main": "index.js",
"license": "ISC",
"bin": {
"snippet": "./index.js"
}
}
And my index.js looks like this:
#!/usr/bin/env node
console.log('Hello World');
I'm testing this module by npm publishing it, and then downloading it to a separate project, because I want to experience it as the user will. The issue is, typing "snippet", I get this message:
-bash: /Users/.../.nvm/versions/node/v6.6.0/bin/snippet: No such file or directory
So I looked online and read that you have to enter the command "npm link". When I enter "npm link" from the test-hello-world directory, the "snippet" command begins to work! However I have never installed an NPM module where I had to type in "npm link" to make it start working.
So what do I have to do so that the command-line interface works right out of the package as soon as test-hello-world is installed?
I tried adding "preferGlobal":"true" to the package, but that didn't seem to make a difference.
Thank you in advance for your help!
via SemperCallide
No comments:
Post a Comment