experienceList:
- dbAnalyst: &dbAnalyst
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex: &webDevXetex
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
# ...
experienceStrategies:
- defaultExperience: &defaultExperience
- <<: *dbAnalyst
- <<: *webDevXetex
- webDevExperience: &webDevExperience
- <<: *webDevXetex
#...
experience: *defaultExperience
配置/default.yml
这导致experience
在 YAML 中输出为:
experience:
- dbAnalyst:
posName: 'Database Analyst / Net Tech'
companyName: 'Choices People Supporting People'
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
现在我想做的是,保留默认值并覆盖它们,在类似于以下的覆盖文件中config/default.yml
选择不同的策略(上述之一):experienceStrategies:
experience: *webDevExperience
配置/覆盖.yml
并希望产生以下结果:
experience:
- webDevXetex:
posName: 'Software Engineer'
companyName: 'Xetex Business Systems'
...
但是,使用 node-config 库时,我会遇到错误;有没有办法在 yaml 和 node.js 中使用其他库或坚持使用 node-config 来做到这一点?我见过另一个名为node-config-yaml 的库,它允许您包含其他 yaml 文件,但不确定它是否允许您以使用node-config
.
/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:933
throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
^
Error: Cannot parse config file: '/home/leeand00/Documents/lifehacker organized/docs/projdir/config/company_job.yml'
: YAMLException: unidentified alias "webDevExperience" at line 14, column 30:
experience: *webDevExperience
^
at util.parseFile (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:
933:11)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:702:28
at Array.forEach (native)
at /home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:698:14
at Array.forEach (native)
at util.loadFileConfigs (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/conf
ig.js:697:13)
at new Config (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config.js:122:
27)
at Object.<anonymous> (/home/leeand00/Documents/lifehacker organized/docs/projdir/node_modules/config/lib/config
.js:1767:31)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)