New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hapi-level

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-level

LevelDB service provider for Hapi

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

hapi-level

A simple LevelDB plugin for Hapi.

Build Status Dependency Status

Note: Sublevel has been updated to v6 in version 3.0.0 which has breaking changes which will corrupt a pre version 6 database, read about the sublevel breaking changes before updating, there is a migration tool to help with the upgrade.

NPM

Register plugin as follows, an optional options object can be passed in to specify data storage location 'path', and the config object supports all LevelUp options:

const Hapi = require('hapi');

var server = Hapi.createServer();
server.connection();

server.register([
    { 
        register: require('hapi-level'),
        options: {
            path: './data', // ./data by default
            config: {
                valueEncoding: 'json' // utf8 by default as with LevelUP
            }
        } 
    }
], (err) => {
    
    if (err) {
        throw err;
    }
    
    server.start((err) => {
    
        if (err) {
            throw err;
        }
        console.log('Server started at: ' + server.info.uri);
    })
};

To use plugin:


// New in 5.0: Make sure either `server.initialize()` or `server.start()` has been called 
// to have access to the db reference

// Accessing level object
const db = request.server.plugins['hapi-level'].db; // access from a request object

// or

const db = plugin.plugins['hapi-level'].db; // access in a hapi plugin

// Usage works just like LevelDB would
db.put('name', 'Level', (err) => {
    
        if (err) {
            return console.log('Ooops!', err); // some kind of I/O error
        }
    
        db.get('two', (err, value) => {
            
            if (err) {
                return console.log('Ooops!', err); // likely the key was not found
            }
    
            console.log('name=' + value);
        });
    });
});

// Sublevel is also available to use for sectioning of data, similar to SQL tables
users.put('two', {id: 2, name: 'Level'}, (err) => {
      
        if (err) {
            return console.log('Ooops!', err); // some kind of I/O error
        }
    
        users.get('two', (err, value) => {
            
            if (err) {
                return console.log('Ooops!', err); // likely the key was not found
            }
    
            console.log(value); // would output {id: 2, name: 'Level'}
        });
    });
});

Keywords

FAQs

Package last updated on 25 Apr 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc