在我的 apps.js 文件中,我有以下代码:
const yargs=require('yargs');
const argv=yargs.argv;
console.log('yargs',argv);
当我正常运行命令时,我得到:
> node app.js read --title="to by"
yargs { _: [ 'read' ],
help: false,
version: false,
title: 'to by',
'$0': 'app.js' }
但是,当我使用nodemon时,如果标题中有空格,我会得到错误的参数:
> nodemon app.js read --title="to by"
yargs { _: [ 'read', '"--title=to', 'by"' ],
help: false,
version: false,
'$0': 'app.js' }
所以应用程序无法正常运行。这里发生了什么?谢谢
我可能会错得很厉害,但在像这样在终端中传递参数时尝试不使用 equals = 。
nodemon app.js read --title "to by"
出于某种原因,如果我在使用 nodemon 时在初始化命令下方的页面中的某处添加 yargs.argv ,控制台只会记录命令结果
const yargs = require("yargs");
yargs.command({
command: "my_command",
describe: "Some Thing is Happening!",
handler: () => console.log("Command is Running."),
});
yargs.argv; // not storing value just mentioning.
在脚本中使用nodemon
"scripts": {
"start": "nodemon index.js"
},
您可以使用
npm start my_command