1. 脚本第一行添加 #!/usr/bin/env node
// index.js
#!/usr/bin/env node
console.log('hello world')
2. package.json 添加bin
{
"name": "hello-test",
"version": "1.0.0",
"bin":{
"hello-cli":"index.js"
}
}
3. npm link
node开发命令行脚本
https://www.cnblogs.com/lcosima/p/11482428.html