A package for Node.js is being developed, in which there is a command line utility. Now alacon.js is a JavaScript program hosted at the root of the package. To run this utility, you must enter the word node before the name of the utility, for example:

node alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2' 

What you need to configure in package.json, what files you need to create and how to make it so that:

1.To run this utility did not need to specify the word node :

 alacon 'SELECT 1+1' 

2. It would be possible to install the package globally and use the utility:

 npm install -g alasql 

That is, to do the same as it is done in Jison, Gulp and many other Node.js utility packages?

    3 answers 3

    As DAiMor and novus42 correctly pointed out, TWO things need to be done:

    package.json

     { "bin" : { "alacon" : "./bin/alacon.js" } } 

    alacon.js

     #!/usr/bin/env node 

    when running npm install -g alasql binary is placed in a directory accessible via PATH.

    In this case, the numbering of parameters will not change. Zero will be node (.exe) and the first is alacon.js .

    • I did everything as you wrote, the system installs npm install -g alasql , then it gives a message that it creates something for these files in the / usr / local / bin directory. But after starting it gives the message '-L: / usr / bin / node: No such file or directory'. I have OSX. Have you encountered such a problem? - agershun 5:43 pm
    • It is not clear how to run, /usr/local/bin/alacon.js Try. And make sure that the first line of your js program finds the node. - exebook
    • Understood, the reason was that it was necessary to replace CRLF with LF in the text alacon.js. Thanks for the help! - agershun pm

    The npm documentation says that for this you need to add in package.json

     { "bin" : { "alacon" : "./bin/alacon.js" } } 

      The standard way in Unix is ​​to write this in the first line:

       #!/usr/bin/env node 

      Then do:

       chmod +x <scriptname> 

      And run accordingly:

       ./scriptname