简体   繁体   English

如何从命令行运行不带“节点”字样的Node.js程序

[英]How to run Node.js program from command line without word 'node'

I am developing the Node.js package, which includes a command-line utility. 我正在开发Node.js程序包,其中包括命令行实用程序。 Now alacon.js is located in the root of the package. 现在, alacon.js位于软件包的根目录中。 To run this utility I have to use word node before the name of utility, like: 要运行此实用程序,我必须在实用程序名称之前使用word node ,例如:

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

Could you help me, what should I change in the package to: 您能帮我吗,我应该将包装中的内容更改为:

1.To run this utility without node word, like: 1.要运行没有node字的实用程序,例如:

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

2.To install this package globally and use the utility everywhere on computer: 2.要全局安装此软件包并在计算机上的任何地方使用该实用程序,请执行以下操作:

 npm install -g alasql
 alacon 'SELECT 2*2'

In other words, how to create utility like Jison, Gulp and other Node.js similar packages with command-line programs. 换句话说,如何使用命令行程序创建实用程序,如Jison,Gulp和其他Node.js类似包。

I already add the #!/usr/bin/env node line to the top of the file, but unfortunately have no desired effect. 我已经在文件顶部添加了#!/usr/bin/env node行,但是不幸的是没有达到预期的效果。

Thank you! 谢谢!

You will need to make the script executable chmod a+x alacon . 您将需要使脚本可执行chmod a+x alacon

Then you should be able to run ./alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2' 然后,您应该可以运行./alacon 'SELECT * FROM CSV("mydata.csv") ORDER BY 2'

If you wish to invoke the script without ./ then you will need to move it (or symlink it) to /usr/bin. 如果您想在不带./的情况下调用脚本,则需要将其移动(或符号链接)到/ usr / bin。

Alternatively - you could create an alias: alias alacon="node alacon" 或者,您可以创建一个别名: alias alacon="node alacon"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM