Skip to content

ideas/hapi-mongoose-connector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hapi Mongoose Connector

npm Build Status Dependency Status

Mongoose connector plugin for the hapi framework.

Installation

npm install --save @ideapod/hapi-mongoose-connector

Configuration

The plugin accepts an options object where:

  • uri: The URI to connect to the MongoDB instance.
const plugin = {
  register: HapiMongooseConnector,
  options: {
    uri: 'mongodb://127.0.0.1:27017/test'
  }
};

If options.uri is not set, MongoDB checks the following environment variables in this order:

  • MONGODB_URI (required): Contains the full MongoDB URI. Example: mongodb://127.0.0.1:27017/test.
  • MONGODB_HOST (required), MONGODB_PORT (required), MONGODB_DATABASE (optional): The plugin uses these variables to construct the URI. Examples: 127.0.0.1, 27017, test.

If options.uri is not set and none of these environment variables are set, an error is thrown on registration.

Usage

The plugin can be registered as a hapi plugin. Example:

const Hapi = require('hapi');
const HapiMongooseConnector = require('@ideapod/hapi-mongoose-connector');

const server = new Hapi.Server();
server.connection();

const plugin = {
  register: HapiMongooseConnector,
  options: {
    uri: 'mongodb://127.0.0.1:27017/test'
  }
};

server.register(plugin, (err) => {
  // ...
});

Connection is exposed and can be accessed through the server object:

const connection = server.plugins['hapi-mongoose-connector'].connection;

About

Mongoose connector plugin for the hapi framework.

Resources

License

Stars

Watchers

Forks

Packages

No packages published