seal-counter-storage

seal-counter-storage manages handling of counters persisted in a MongoDB

Usage no npm install needed!

<script type="module">
  import sealCounterStorage from 'https://cdn.skypack.dev/seal-counter-storage';
</script>

README

seal-counter-storage

CircleCI AppVeyor

seal-counter-storage manages handling of counters persisted in a MongoDB.

Installation

$ npm install seal-counter-storage

Quick start

First you need to add a reference to seal-counter-storage within your application.

var counterStorage = require('seal-counter-storage');

Then you can connect to a MongoDB. For that call the connect function and provide the database's connection string using the url property:

counterStorage.connect({ url: 'mongodb://localhost:27017' }, function (err, storage) {
  // ...
})

Optionally, you may also specify the number of connection retries:

counterStorage.connect({
  url: 'mongodb://localhost:27017',
  connectionRetries: 10
}, function (err, storage) {
  // ...
})

Get next counter value

To get the next counter value call the getCounter function and provide at least its name and a callback. Optionally you can provide the increment as second argument, default increment is 1.

storage.getCounter('hugo', function (err, newCounterValue) {
  // ...
});

With increment:

storage.getCounter('hugo', 100, function (err, newCounterValue) {
  // ...
});

Running the build

To build this module use roboter.

$ bot