简体   繁体   中英

Node Command Line Tool with NVM bash:not found

I am writing a simple node CLI tool and having trouble using with NVM. Even installed node locally and use nvm use system and the CLI file still cannot be found. Code is simply including the shell designation:

#!/usr/bin/env node

console.log("Hello, here is my first CLI tool")

When running this from command line I get this: -bash: cli-project: command not found

Have tried everything. Node is at /usr/local/bin/node, and have even added that. Have used system location of node. Have added the path to /etc/paths. Nothing works? Does anyone have experience building a node CLI tool using NVM how to set up initially, NVM is set up correctly on my machine. and.bash_profile is fine. Very puzzling why it won't pick up this simple path to this.

You have to do a little package.json magic in addition to the shebang it seems like so:

"bin": {
    "cli-project": "index.js"
  },

Then do npm link. in the application directory. Works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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