如何从命令行运行不带“节点"字样的Node.js程序 [英] How to run Node.js program from command line without word 'node'
问题描述
我正在开发Node.js程序包,其中包括一个命令行实用程序.现在, alacon.js 位于包的根目录中.要运行此实用程序,我必须在实用程序名称之前使用单词 node
,例如:
I am developing the Node.js package, which includes a command-line utility. Now alacon.js is located in the root of the package. To run this utility I have to use word node
before the name of utility, like:
node alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2'
您能帮我吗,我应该将包装中的内容更改为:
Could you help me, what should I change in the package to:
1.要运行不带 node
字样的实用程序,例如:
1.To run this utility without node
word, like:
alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2'
2.要全局安装此软件包并在计算机上的任何地方使用该实用工具,
2.To install this package globally and use the utility everywhere on computer:
npm install -g alasql
alacon 'SELECT 2*2'
换句话说,如何使用命令行程序创建实用程序,如Jison,Gulp和其他Node.js类似包.
In other words, how to create utility like Jison, Gulp and other Node.js similar packages with command-line programs.
我已经在文件的顶部添加了#!/usr/bin/env节点
行,但是不幸的是没有达到预期的效果.
I already add the #!/usr/bin/env node
line to the top of the file, but unfortunately have no desired effect.
谢谢!
推荐答案
您将需要使脚本可执行 chmod a + x alacon
.
You will need to make the script executable chmod a+x alacon
.
然后,您应该可以运行./alacon'SELECT * FROM CSV("mydata.csv")ORDER BY 2'
Then you should be able to run ./alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2'
如果您希望在不使用 ./
的情况下调用脚本,则需要将其移动(或符号链接)到/usr/bin.
If you wish to invoke the script without ./
then you will need to move it (or symlink it) to /usr/bin.
或者-您可以创建一个别名: alias alacon ="node alacon"
Alternatively - you could create an alias: alias alacon="node alacon"
这篇关于如何从命令行运行不带“节点"字样的Node.js程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!