application.js 408 B

12345678910111213141516
  1. 'use strict';
  2. const fs = require('fs');
  3. const util = require('util');
  4. const readFile = util.promisify(fs.readFile);
  5. module.exports = {
  6. async readConfig(path) {
  7. try {
  8. const data = await readFile(path);
  9. return JSON.parse(data);
  10. } catch (error) {
  11. const body = { errcode: -1000, errmsg: '读取配置文件失败', error };
  12. throw new Error(JSON.stringify(body));
  13. }
  14. },
  15. };