[英]node.js Command Line Interface app on windows
在package.json
文件中,您需要编写如下代码:
"name" : "test",
"version": "1.0.0",
"scripts": {
"start": "node index.js",
"build": "webpack",
},
...
...
之后,使用命令npm start
运行该应用程序。
1-在根文件夹中创建bin文件夹,然后将index.js放入bin中。 在index.js的第一行输入shebang代码:
bin / index.js
#!/usr/bin/env node
console.log("hello world");
2-将以下代码添加到package.json文件中。
"bin": {
"test": "./bin/index.js" //this is relative path
}
3最终在命令行上运行此代码
npm link
现在您在命令行中运行“ test”,它将记录“ hello world”
注意:请注意我上面提到的相对路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.