🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

fs-key-value

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fs-key-value

Key value data store using the filesystem

Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

fs-key-value

This module provides a simple key value data store using only the file system. It makes use of file locking to allow safe operation in a multiple process environment without the overhead of a separate database server.

NPM

Installation

$ npm install fs-key-value

Example

var cluster = require('cluster'), 
    FsKeyValue = require('fs-key-value')

if (cluster.isMaster) {
  for (var i = 0; i < 8; i++) {
    cluster.fork()
  }
} else {
  var id = cluster.worker.id % 2

  var mydb = new FsKeyValue('./mydb', function (err, db) {
    if (err) {
      return console.log(err)
    }

    db.put('hoopla' + id, {'msg': 'ballyhoo ' + cluster.worker.id}, function (err) {
      if (err) {
        return console.log(cluster.worker.id + ' err ' + err)
      }

      db.get('hoopla' + id, function (err, data) {
        if (err) {
          return console.log(cluster.worker.id + ' err ' + err)
        }

        if (data != undefined) {
          console.log(data.msg)
        }

        db.delete('hoopla' + id)

        cluster.worker.kill()
      })
    })
  })
}

Keywords

key

FAQs

Package last updated on 21 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts