节点js需要json使用变量(var)

时间:2015-03-16 05:48:22

标签: javascript node.js

我想要./../bin/<variable>.json。所以我将var设为var (reqLink = "'./../bin/"+lanID+".json'")并传递给(var engJason = require(reqLink)),但它不起作用。但它确实适用于像(var engJason = require('./../bin/eng.json');)

这样的相对路径
var reqLink = "'./../bin/"+lanID+".json'";
var engJason = require(reqLink);

//Not working ||error Cannot find module ''./../bin/eng.json''

1 个答案:

答案 0 :(得分:1)

删除额外的单引号:

"'./../bin/"+lanID+".json'" =&gt; "./../bin/" + lanID + ".json"