This SO answer describes use of the process.argv
variable to access command line arguments when using node.js to run a javascript file。如何使用node.js從.json文件而不是命令行訪問參數?
Here is the source documentation for process.argv
。
但是,如果我的參數存儲在.json文件中,而不是單獨在命令行中輸入,該怎麼辦?有沒有辦法使用node.js訪問它們?
data.json{
"foo": "bar",
"baz": "bat"
}
我想加載data.json作爲參數以某種方式爲我的js文件,我也有我的計算機上本地存儲。然後運行它。
app.jsvar foo = "bar",
baz = "bat"; // Somehow, I need to import these arguments from data.json
// Then do stuff with them...