我当前使用的版本
node v8.11.1
npm v5.6.0
1.创建一个index.js文件,内容如下:
#! /usr/bin/env node
console.log('hello shell')
#! /usr/bin/env node这句话是一个shebang line实例, 作用是告诉系统运行这个文件的解释器是node;
例如,本来需要这样运行node index.js,但是加上了这句后就可以直接index.js运行了
2.用npm init创建一个package.json文件,修改后如下:
{
"name": "shell",
"bin": {
"hello": "index.js"
},
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC"
}
3.执行npm link,输出如下:

运行一下试试看吧,成功了,结果如下:

网友评论