简体   繁体   中英

Node.js: Custom command line interface

I'm very newbie in this thing. I would like to create a command line interface for my application where I can specify custom commands something like these:

myapp new /root/myapp
myapp start /server.js
myapp stop /server.js

So i can interact with my application just like I do with a real service like mysql. Is it possible to write such a service like thing inside node.js?

What I'm looking for something similar to forever or meteor in terms of working with them.

Thanks for any help!

You need to specify myapp in package.json like so:

{ "name": "myapp"
, "version": "0.0.1"
, "engines": [ "node >=0.4.0" ]
, "description": "myapp command line util."
, "author": "..."
, "contributors": []
, "keywords" : [ "myapp", "command", "shell" ]
, "repository":
  { "type" : "git"
  , "url" : "https://...."
  }
, "bin" : { "myapp" : "./bin/myapp.js" }
}

http://howtonode.org/how-to-module

You can use commander module from npm for building your own CLI. Simply enter:

npm install commander 

This will install commander module.

For examples and documentation, you can go through this: https://www.npmjs.com/package/commander

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