最近在使用TypeScript编写后台接口时,需要读取yaml配置文件,使用到了yaml这个nodejs库,其npm官网地址为:https://www.npmjs.com/package/yaml,github源代码地址为:github.com/eemeli/yaml
比如有如下的config.yaml配置文件:
rxmqtt:
host: 127.0.0.1
port: 11883
user: testuser
pwd: "123456"
id: "this_is_test_2000804_nodejs_water"
clean: true
dbsql:
host: 127.0.0.1
port: 3306
user: root
pwd: "123456"
database: testdb
redis:
host: 127.0.0.1
port: 7001
pwd: 123456
index: 0
http: 8088
rpcUrl: 127.0.0.1:18885
enableMqtt: true
enableDB: true
enableRedis: true
enableWS: true
enableRPC: false
offlineTimeout: 90000
cacheInterval: 10000
使用typescript针对上述config.yaml文件编写对应的config.ts文件如下: