bitquery-mongo-reader
v0.1.0
Published
Express app for reading Bridge data from a Mongo database
Downloads
3
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.
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:
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
Table of Contents
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? All parameters are given in an object. All parameters are optional. (optional, default{}
)obj.documentationFileName
String? Path to a .md file containing bridge protocol documentation. Overriden if theDOCUMENTATION_FILE_NAME
environmental variable is present.obj.bridge
Object? The Bridgeport bridge object. Overriden if theBRIDGE
environmental variable is present. Either the environmental variable or this parameter are required.obj.defaultQuery
String? The default query for the web UI, given as a formatted JSON string. Overriden if theDEFAULT_QUERY
environmental variable is present.obj.defaultSocket
String? The default socket for the web UI, given as a formatted JSON string. Overriden if theDEFAULT_SOCKET
environmental variable is present.
Returns Promise A Promise for an Express app instance
License
The license for the code in this repository is the Open BSV License.