All Projects → lmammino → mongo-uri-builder

lmammino / mongo-uri-builder

Licence: MIT license
A node.js module to easily create mongodb connection strings using configuration objects

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to mongo-uri-builder

Solidarity
Solidarity is an environment checker for project dependencies across multiple machines.
Stars: ✭ 540 (+1762.07%)
Mutual labels:  javascript-library, node-js
Rando.js
The world's easiest, most powerful random function.
Stars: ✭ 659 (+2172.41%)
Mutual labels:  javascript-library, node-js
Adder
Executing untrusted code with ease.
Stars: ✭ 45 (+55.17%)
Mutual labels:  javascript-library, node-js
trifolia-on-fhir
Sister product to Trifolia Workbench that has native support for FHIR resources
Stars: ✭ 23 (-20.69%)
Mutual labels:  node-js
w-components
JavaScript library based on Web Components.
Stars: ✭ 17 (-41.38%)
Mutual labels:  javascript-library
Online-Chess
A chess website where people can play against each other online.
Stars: ✭ 28 (-3.45%)
Mutual labels:  node-js
ChaRo-Server
🚙 서버가 걸어다니면? 서버억,,서버억,,, 🚙
Stars: ✭ 18 (-37.93%)
Mutual labels:  node-js
content-moderation-image-api
An NSFW Image Classification REST API for effortless Content Moderation built with Node.js, Tensorflow, and Parse Server
Stars: ✭ 50 (+72.41%)
Mutual labels:  node-js
Registration-and-Login-using-MERN-stack
Simple Registration and Login component with MERN stack
Stars: ✭ 210 (+624.14%)
Mutual labels:  node-js
midtrans-nodejs-client
Official Midtrans Payment API Client for Node JS | https://midtrans.com
Stars: ✭ 124 (+327.59%)
Mutual labels:  node-js
recent-activity
Add your recent activity to your profile readme!
Stars: ✭ 87 (+200%)
Mutual labels:  node-js
MLweb
Machine learning and scientific computing (linear algebra, statistics, optimization) javascript libraries, with an online lab.
Stars: ✭ 85 (+193.1%)
Mutual labels:  javascript-library
node-ctrip-tickets
🚄🚄🚄 Node.js 携程火车票查询,查询有票的列车
Stars: ✭ 12 (-58.62%)
Mutual labels:  node-js
party-js
A JavaScript library to brighten up your user's site experience with visual effects!
Stars: ✭ 858 (+2858.62%)
Mutual labels:  javascript-library
enterprise
Enterprise-grade component library for the Infor Design System
Stars: ✭ 117 (+303.45%)
Mutual labels:  javascript-library
backend-server
📠 The backend of the Fairfield Programming Association website.
Stars: ✭ 26 (-10.34%)
Mutual labels:  node-js
groucho
Know all your users. Scalable front-end (anon) personalization & attribution
Stars: ✭ 31 (+6.9%)
Mutual labels:  javascript-library
biguint-format
Node.js module to format big uint numbers from a byte array or a Buffer
Stars: ✭ 16 (-44.83%)
Mutual labels:  node-js
TinyPNGNodeJSBatcher
提供一个NodeJS环境下,基于TinyPNG服务的,批量压缩任意数量图片的工具。
Stars: ✭ 51 (+75.86%)
Mutual labels:  node-js
Tweet-Analysis-With-Kafka-and-Spark
A real time analytics dashboard to analyze the trending hashtags and @ mentions at any location using kafka and spark streaming.
Stars: ✭ 18 (-37.93%)
Mutual labels:  node-js

mongo-uri-builder

A zero dependency Node.js module to easily create MongoDB connection strings using configuration objects

Tests npm version codecov

NPM

Rationale

Most of the existing MongoDB libraries (e.g. the official MongoClient or Mongoose) uses connection strings to connect to your running mongo instances which most of the times is very quick and convenient. Anyway sometime you want to have your MongoDB connection details organized in a nice javascript object so that you can easily serialize it in a configuration file and be able to override some specific values in different environments (e.g. "development" or "production") without having to override the entire connection string.

With this module you can easily accomplish this goal and in general you will be able to easily generate a MongoDB connection string starting from an organized javascript object that you can manipulate as you wish.

Quick example

var mongoUriBuilder = require('mongo-uri-builder');

var connectionString = mongoUriBuilder({
	username: 'user', // or user: 'user'
	password: 'pass',
	host: 'host1',
	port: 1111,
	replicas: [
		{host: 'host2', port: 2222},
		{host: 'host3', port: 3333}
	],
	database: 'db',
	options: {
		w: 0,
		readPreference: 'secondary'
	}
});

console.log(connectionString); 

// prints "mongodb://user:pass@host1:1111,host2:2222,host3:3333/db?w=0&readPreference=secondary"

Install

As easy as running:

npm install --save mongo-uri-builder

Requires Node.js 8+

Usage

As shown in the previous example the module exposes just a function that accepts an optional structured object as parameter. If no parameter is given the default MongoDB://localhost will be built.

Available options:

All the options are optional and the following example describes all the available ones:

{
	username: 'user', // the username
	// user: 'user', // this is alternative of username
	password: 'pass', // the password
	host: 'host1', // the main host (default: "localhost")
	port: 1111, // the main port
	replicas: [ // an array of replica databases
		{host: 'host2', port: 2222}, // every replica must define an host, the port is optional
		{host: 'host3', port: 3333}
	],
	database: 'db', // the name of the database
	options: { // an arbitrary object of connection options
		w: 0,
		readPreference: 'secondary'
	}
}

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

You can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.

Code standard

XO conventions and tools are used as code standard. You can easily check if your edits conforms the standard by running:

npm run check-style

Tests

Tape is used as default test runner. You can easily run the tests by using:

npm run tests

Coverage

Covert can be used to check tests coverage by running:

npm run coverage

License

Licensed under MIT License. © Luciano Mammino.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].