npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@42nth/mrepset

v0.2.0

Published

Create a local mongo replica set for dev or testing

Downloads

7

Readme

MongoDB Replica Set

Warning

This script is meant to be used only for dev & testing environment as it comes with no security setup.

It should only be used for localhost or on any secured environment, not into the global internet.

Description

This script will configure a MongoDB replica set environment and start all the replica set mongod processes.

By default it will create a replica set rs of 3 nodes on localhost with a db path of /srv/mongo:

  • node #1, rs-0 on port 27017,
  • node #2, rs-1 on port 27018,
  • node #3, rs-2 on port 27019.

Each process will have its own log files streamed to disk :

  • access log : <dbPath>/log/rs-X/access.log,
  • error log : <dbPath>/log/rs-X/error.log.

Closing the main process will terminate the three processes.

Installation

Locally :

  • npm : npm i @42nth/mrepset
  • yarn : yarn add @42nth/mrepset

Or globally :

  • npm : npm i -g @42nth/mrepset
  • yarn : yarn global add @42nth/mrepset

Usage

const setup = require('mrepset')

setup(options)

Options

Replica Set options

name (default: 'rs')

The name of the replica set.

baseDir (default '/srv/mongodb')

The base directory of the MongoDB instance. Must be writable by the current user or the process will failed.

port (default 27017)

Default MongoDB port. You can override it to any value N you want and it will use the value N, N+1 and N+2 for the 3 nodes.

oplog (default 128)

Use a slow value by default as it should only be used for testing purposes. Not the values you would use in production.

nodes (default 3)

The number of nodes to create in the replicat set.

ip (default '127.0.0.1')

The ip the server will listen to.

Generic options

mongodPath

The path to find the MongoDB binaries. Useful if you have multiple MongoDB versions to point a specific MongoDB version bin path.

accessLog (default 'access.log')

The name of a node access log file.

errorLog (default 'error.log')

The name of a node error log file.

Examples

Programmatically

In the example below a replica set of 3 nodes starting on port 27117, 27118 & 27119 using a [email protected] installation in /usr/local/opt/[email protected] folder :

const setup = require('@42nth/mrepset')

setup({
  rs: {
    port: 27117,
    baseDir: '/opt/mongodb'
  },
  mongo: {
    mongodPath: '/usr/local/opt/[email protected]/bin',
  }
})

You can see a local version in the examples/setup.js file.

CLI

This module export the mrepset CLI.

$ mrepset --baseDir /opt/mongodb

Access all options :

$ mrepset --help

If you want to access debug logs add the DEBUG flag on the CLI with the mongo:rs flag.

You can see a local version in the examples/setup.sh file which can be run :

$ ./examples/setup.sh