Javascript 使用node和gulp解析json文件
现在我正在浏览gulpfile中的代码,并将其发送到适当的位置。但是,如果我想解析json文件并在index.html中显示它 它返回以下错误:Javascript 使用node和gulp解析json文件,javascript,node.js,gulp,Javascript,Node.js,Gulp,现在我正在浏览gulpfile中的代码,并将其发送到适当的位置。但是,如果我想解析json文件并在index.html中显示它 它返回以下错误: Uncaught TypeError: require(...).readFileSync is not a function 这是我的gulpfile和app.js的代码 我错过什么了吗?为什么我不能使用普通的节点模块来处理这种事情?您应该能够直接在节点中要求JSON文件: var myJson = require('./path/to/file.
Uncaught TypeError: require(...).readFileSync is not a function
这是我的gulpfile和app.js的代码
我错过什么了吗?为什么我不能使用普通的节点模块来处理这种事情?您应该能够直接在节点中要求JSON文件:
var myJson = require('./path/to/file.json');
// log to confirm output
console.log(JSON.stringify(myJson));
这假设file.json
是原始json,大致如下:
{
"property": "value",
"property2": "value2"
}
您应该能够直接在节点中要求JSON文件:
var myJson = require('./path/to/file.json');
// log to confirm output
console.log(JSON.stringify(myJson));
这假设file.json
是原始json,大致如下:
{
"property": "value",
"property2": "value2"
}
我猜您使用的是
fs
。只需导入fs
,然后使用fs.readFileSync()
@添加的代码。很抱歉,我猜您使用的是fs
。只需导入fs
,然后使用fs.readFileSync()
@添加的代码。对不起