比如在很多php py 文件中!都会从命令行接受参数的值并带入程序中!
我也想用node.js这么写 我目前是这样写的 感觉太费劲了!
var options = process.argv;
for(var i=0;i<canshu.length;i++)
{
if(options[i].indexOf("-string")==0)
{
。。。。。
}
else if(options[i].indexOf("--start")==0)
{
........
}
}
感觉这样好费劲 有什么更加好一点的方法没?
Look at tj’s commander.js
https://github.com/visionmedia/commander.js
Code Example
The commander mentioned above is specially used to write CLI. If you just need a package that specifically parse command line parameters, you can use substack's optimist: https://npmjs.org/package/optimist
I suggest you visit morehttps://npmjs.org/browse/star
The library inside is basically complete
NoteThe following procedures are essential. @0x_Jin Look at how this article is written
http://witcheryne.iteye.com/blog/1196170