【发布时间】:2017-11-12 17:04:07
【问题描述】:
我使用命令 node app.js 运行 app.js
它执行const inputData = require('./input.json');
是否可以从命令行将文件名作为参数传递给const inputData = require('./file.json');?我的意思是:
node app.js file.json
我对这个诡计完全陌生,没有理论意义。我应该从哪里开始?非常感谢所有可能的帮助。
非常感谢,
【问题讨论】:
-
您有
process.argv可以访问命令行参数stackoverflow.com/a/4351548/3410584。然后只需require与良好的索引
标签: javascript json node.js terminal