- 参数在方法体内不加''()'',则正常使用,加"()"并且括号内有值则会返出去
const fs = require('fs');
const path = require('path');
function getJsonFromConfig(c,filePath) {
fs.readFile(path.join(__dirname, c), `utf-8`, (err, res) => {
if (err) {
// reject(err);
}
filePath(JSON.parse(res));
});
}
getJsonFromConfig(`../config/config.json`,aa => {
console.log(`-----=====`, aa);
});
const fs = require('fs');
const path = require('path');
async function getJsonFromConfig() {
var promise=new Promise((resolve, reject) => {
fs.readFile(path.join(__dirname, `../config/config.json`), `utf-8`, (err, res) => {
if (err) {
reject(err);
}
resolve(JSON.parse(res));
});
});
var data = await promise;
console.log(`-----data=====`, data)
return data
}
var b = async function () {
var data = await getJsonFromConfig()
console.log(`-----aaaaaaa=====`,data)
}
b()
var configPath = path.join(__dirname, `../../config/config.json`);
var deviceType = JSON.parse(fs.readFileSync(configPath))[`deviceType`];
网友评论