使用 node 和 gulp 解析 json 文件

Mod*_*esq 0 javascript node.js gulp

现在我正在浏览 gulpfile 中的代码,并将其发送到适当的位置。但是,如果我想解析一个 json 文件并在 index.html 中显示它...

它返回此错误:

Uncaught TypeError: require(...).readFileSync is not a function
Run Code Online (Sandbox Code Playgroud)

这是我的 gulpfile 和 app.js 的代码http://pastebin.com/n0BJfZG9

我错过了什么吗?为什么我不能为这种事情使用普通的节点模块?

Ste*_*Dev 5

您应该能够直接在节点中要求您的 JSON 文件:

var myJson = require('./path/to/file.json');

// log to confirm output
console.log(JSON.stringify(myJson));
Run Code Online (Sandbox Code Playgroud)

这假设file.json是原始 JSON,如下所示:

{
  "property": "value",
  "property2": "value2"
}
Run Code Online (Sandbox Code Playgroud)