Code Monkey home page Code Monkey logo

node-utils's Introduction

Simple Node.js Utils

bitHound Overall Score bitHound Dependencies bitHound Code

Install

npm install github:perusworld/node-utils --save

Usage

See the test cases for detailed usage

Session (in memory cache with loader support)

var sessionapi = require('node-utils').session();
var session = new sessionapi.Session({});

session.load('key', 'prop', true, (callback) => {
      callback(null, 'a loaded value')
    }, (err, loadedValue) => {
      //handle loaded value
});

Dumper (dump objects to json with timestamped filenames)

var dumperapi = require('node-utils').dumper();
var dumper = new dumperapi.Dumper({});

//Don't care about the save status
dumper.dump('some-prefix', objectToDump);

//Care about the save status
dumper.dump('some-prefix', objectToDump, (err, filename) => {
  //handle save status
});

DataSource/Model (Simple datasource/model wrapper for mondogb)

var datasourceapi = require('node-utils').datasource();
new datasourceapi.DataSource({ mongodbURI: 'mongodb://localhost:27017/my-db' }, (err, datasource) => {
  var aColModel = new datasourceapi.Model(datasource, 'some-collection');
  ctx.aColModel.add(myObj, (err, resp) => {
    //resp._id has the object id
  })

});

nonce

var datasourceapi = require('node-utils').datasource();
new datasourceapi.DataSource({ mongodbURI: 'mongodb://localhost:27017/my-db' }, (err, datasource) => {
    new datasourceapi.Nonce({ 
      oneTimeUse: true, 
      expireAfterSeconds: expireAfterSeconds 
      }, datasource, (err, nonceModel) => {
        nonceModel.addNonce('someKey', (err, nonce) => {
          //use nonce
        });
    });

});

node-utils's People

Contributors

perusworld avatar

Watchers

 avatar James Cloos avatar

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.