Code Monkey home page Code Monkey logo

nodecfglib's Introduction

一个基于MongoDB的NodeJs系统配置操作库。

NodeCfgLib是一个基于MongoDB的Node.js系统配置库。

可以方便地设置存储系统相关配置,以配置名-配置(JSON)的形式存储。

Import

安装及配置MongDB数据库。

将src下面的文件放入你的工程,将package.json中依赖的选项合并到你的工程。

import db from './src/mongodbLib'

注:本库使用ES6语法以及ES7中的async特性,请使用babel。

API

setConfig 保存(修改)配置

db.setConfig('test',{a:111,b:222}, function(){})})

getConfig 获取当前配置

db.getConfig('test', function(d){
	console.log('getConfig',d);
})

setDefault 设置默认配置

db.setDefault('test',{a:333,b:555}, function(){})

getDefault 获取默认配置

db.getDefault('test', function(d){
	console.log('default',d);
}

attach 注册配置回调函数(保存成功后回调)

let func = function(config){console.log('cfg1', config)}
db.attach('test', func);                             

detach 注销配置回调函数

db.detach('test', func);

attachVerity 注册配置钩子函数(在保存之前检测配置的数据的钩子函数,如果该函数返回false则不继续保存该配置)

db.attachVerity('test', function(d){return true;})

detachVerity 注销配置钩子函数

db.detachVerity('test', function(){})

restore 将默认配置设置给当前配置

db.restore('test')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.