# bitquery-mongo-reader

> Express app for reading Bridge data from a Mongo database

Latest version **0.1.0** (published 2022-10-14) · Open BSV License license · 0 weekly downloads

## Install

```sh
npm install bitquery-mongo-reader
pnpm add bitquery-mongo-reader
yarn add bitquery-mongo-reader
bun add bitquery-mongo-reader
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2022-10-14 |
| First published | 2022-10-14 |
| Weekly downloads | 0 |
| License | Open BSV License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 2.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tyeverett |

## Links

- npm: https://www.npmjs.com/package/bitquery-mongo-reader
- npm.io page: https://npm.io/package/bitquery-mongo-reader

## Dependencies (6)

- [ejs](https://npm.io/package/ejs.md) ^3.1.6
- [cors](https://npm.io/package/cors.md) ^2.8.5
- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0
- [express](https://npm.io/package/express.md) ^4.17.1
- [mongodb](https://npm.io/package/mongodb.md) ^4.1.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0

## Recent versions

- 0.1.0 (latest) — 2022-10-14

## README

# bitquery-mongo-reader

Express app for reading Bridge data from a Mongo database

## Overview

This is a reader for use with bridges that utilizes Bitquery and MongoDB for document storage and retrieval. Reader protocol documentation can be specified with a `.md` markdown file, and common configuration options can be provided with either environmental variables or programatically.

The environmental variables `DEFAULT_QUERY` and `DEFAULT_SOCKET` are used to specify the query strings a user starts with in their query and listening socket UI fields. These can be edited by the user, during the session, to create new queries or listening sockets.

Configuration of these variables, as well as the other variables required by all bridge readers (`BRIDGE`, `PORT`, etc.), can be accomplished by passing environmental variables, or programatically, as shown in the example below.

Bitqueries sent to the Reader must be in strict full JSON format and follow the [Bitquery spec](https://projectbabbage.com/docs/bridgeport/reference/bitquery).

This is an NPM package that exports a function. Calling the function will:

*   Create an Express app
*   Connect to the Bridge database
*   If connection fails, try again every 3 seconds
*   Once connected, set up the Bridge Reader routes
*   Finally, start listening for HTTP requests, and return the Express app

## Example

You can install the package as follows:

    npm i bitquery-mongo-reader

Then, you can start it within JavaScript like so:

```js
const reader = require('bitquery-mongo-reader')
const path = require('path')
reader({
  documentationFileName: path.join(__dirname, 'my-protocol-docs.md')
})
```

You could then, for example, start the above JavaScript program with appropriate `BRIDGE`, `PORT`, and `MONGO_READ_CREDS` variables, and the reader will start serving.

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

*   [index](#index)
    *   [Parameters](#parameters)

### index

Creates and returns an Express app bound to the given port. Values provided by the specified environmental variables override those provided here.

#### Parameters

*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** All parameters are given in an object. All parameters are optional. (optional, default `{}`)

    *   `obj.documentationFileName` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Path to a .md file containing bridge protocol documentation. Overriden if the `DOCUMENTATION_FILE_NAME` environmental variable is present.
    *   `obj.bridge` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** The Bridgeport bridge object. Overriden if the `BRIDGE` environmental variable is present. Either the environmental variable or this parameter are required.
    *   `obj.defaultQuery` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The default query for the web UI, given as a formatted JSON string. Overriden if the `DEFAULT_QUERY` environmental variable is present.
    *   `obj.defaultSocket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** The default socket for the web UI, given as a formatted JSON string. Overriden if the `DEFAULT_SOCKET` environmental variable is present.

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise for an Express app instance

## License

The license for the code in this repository is the Open BSV License.

---
_Source: https://npm.io/package/bitquery-mongo-reader · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
