I try to create a simple Node.js command line tool to get around this concept. I am following this tutorial. Using npm init, I have created a project named lb-model-discovery. This is the content of the package.json:
{
"name": "lb-model-discovery",
"version": "1.0.0",
"description": "loopback model discovery command line tool",
"main": "index.js",
"bin" :{
"lb-discover":"./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "seya obey",
"license": "ISC"
}
And this is the (very simple) content of the index.js at the root of the project:
console.log('hello world');
After that I executed this command from within the folder (as suggested by the above tutorial):
npm install -g
This correctly install my tool as a global Node command line module. Going into the global repository of node_modules/ in my system (Windows), I can see that this is the file created in the npm folder: lb-discover.cmd. And here is its content:
@"%~dp0\node_modules\lb-model-discovery\index.js" %*
But now when I run my new tool from the command line prompt:
$ lb-discover
instead of displaying a "Hello world" message in the console, it opens Notepad instead and merely displays the content of the index.js file.
What am I doing wrong? How can I execute my custom Node.js command line?