0
我有以下的輔助方法:產量與promisified READFILE返回undefined
module.exports.rootUrl = co(function*() {
const jsonPath = path.resolve(process.cwd(), './server/config.json');
console.log(jsonPath);
let config;
try {
const readFile = Promise.promisify(fs.readFile);
const config = yield readFile(jsonPath, 'utf-8');
} catch (err) {
console.dir(err);
yield Promise.reject(err);
};
console.dir(config);
const url = `http://${config.host}:${config.port}/${config.restApiRoot}`;
console.log(url);
yield Promise.resolve(url);
})
的問題是,調用yield. readFile(jsonPath, 'utf-8')
被返回undefined。