V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
sox
V2EX  ›  分享创造

更简单地管理 Node.js 命令行程序里的配置文件

  •  
  •   sox ·
    egoist · 2015-10-21 22:31:25 +08:00 · 1338 次点击
    这是一个创建于 3274 天前的主题,其中的信息可能已经有所发展或是发生改变。

    很多时候一个命令行程序会往 USER_HOME 目录保存一些 config 文件,比如 .gitconfig .zshrc

    所以我造了个轮子 myconf 用来管理这些 config 文件

    很简单的 API:

    import Config from 'myconf'
    
    // This points to a file $USER_HOME/.customconfig
    const config = new Config('.customconfig')
    
    config
      .set('name', 'config for my project')
      .then(data => console.log(data.name))
    
    config
      .get('name')
      .then(name => console.log(name))
    

    一个使用此包的例子: https://github.com/egoist/toka


    GitHub 仓库: https://github.com/egoist/myconf

    NPM 安装: npm i -S myconf

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1456 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.