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 🙏

© 2026 – Pkg Stats / Ryan Hefner

backup-mongodb

v0.1.1

Published

This module will backup mongodb into a .zip archive and optionally send it to a email address

Readme

backup-mongodb

This module will backup mongodb into .json files, archive it into .zip file that is then send to provided emil address using nodemailer automatically

Motivation

I wrote this module as a simple straight forward module for backing up mongodb. I also realized that I need the backup file in an external environment other than the server (which of course is the essence of backup). Thus, I added the feature to zip the output .json files and then send them to an email using nodemailer. From the email, I can access the files and use them for restoration anytime later.

The backup output files are named in the format dbName_day_month_year.hour.mins.second e.g. test_21_9_16.4.33.0

This makes it easy to know which file is the latest backup and for reference sake

After using this module to create a backup, you can use the accompanying module backup-mongodb-restorer to restore the .zip file to the database

Please read on to get full understanding of how it works.

Installation

npm install -save backup-mongodb

Usage Example

Without Email Configuration


var dbUri = "mongodb://127.0.0.1:27017/test";

//example dbUri with username and password for the database test
// var dbUri = "mongodb://username:[email protected]:27017/test";


var basePath = "./backup";
var Backup = require("backup-mongodb");

new Backup(dbUri, basePath).backup();

//optionally you can call new Backup(dbUri, basePath).backup(done);
//where done is the callback to be called when done

With Email Configuration


var dbUri = "mongodb://127.0.0.1:27017/test";

//example dbUri with username and password for the database test
// var dbUri = "mongodb://username:[email protected]:27017/test";


var basePath = "./backup";
var Backup = require("backup-mongodb");

//========= email configs ========

var emailSubject = "DATABASE BACKUP"; 
var emailText = "This email contains an attachment of the backup of your mongodb in zip format";

var smtpOptions = {
 	host: "your.mailserver.hostdomain.com",
	port: "the port on which your mail server is running",
	auth: {
		user: "[email protected]",
		pass: "your password for the email user above"
	   },
	tls : { 
		rejectUnauthorized: false,
		secureProtocol: "TLSv1_method"
		}
	};


	var emailOptions = {
		from: "[email protected]",
		to: "[email protected]",
		subject: emailSubject,
		text: emailText
	}

//======== now do the backup ==========

new Backup(dbUri, basePath, smtpOptions, emaiOptions).backup();

//optionally you can call new Backup(dbUri, basePath, smtpOptions, emaiOptions).backup(done);
//where done is the callback to be called when done

NOTE:

* To know more about the smtpOptions and emailOptions, kindly head over to the docs of

nodemailer project.

* You have to supply both the smtpOptions and emailOptions for your zip file to be sent to the designated email address.

* Provide the authentication to the desired database in the dbUri string

API Reference

params


* dbUri [required]: the uri of the desired database

* basePath: The output folder e.g. "./backup"

* smtpOptions [required for email] {
		host: "your.mailserver.hostdomain.com",
		port: "the port on which your mail server is running",
		auth: {
			user: "[email protected]",
			pass: "your password for the email user above"
			},
		tls : { 
			//optional but useful config for non-secure/secure connection
			rejectUnauthorized: false,
			secureProtocol: "TLSv1_method"
		}	
	}

* emailOptions [required for email] {
		from: "[email protected]",
		to: "[email protected]",
		subject: "Email Subject",
		text: "Email Body text"
	}

Note

  • Always check your spam folder for emails sent as some may end up there. Which you can mark as not spam for future cases

  • Please I strongly recommend, if you haven't yet, that you go and read the nodemailer documentation for more understanding of the email config options

  • Provide the authentication to the desired database in the dbUri string

Test

clone this git repo and cd into it.

then run $ npm install to install all the dependencies

then run the command $ npm test to run the tests

Note:

  • You will need to have make installed on your system to run the test for windows

  • If you want to run on other OS other than windows, you might want to Open the makefile in the project root dir and then change the path separator in .\node_modules.bin\mocha

Contributors

Author: Seun Matt (twitter @SeunMmatt2)

To contribute to this project kindly create a pull request. Open an issue for discussion for the added feature(s)

LICENSE

MIT License