
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
appbase-js
Advanced tools
Appbase.io streaming client lib for Node.JS and Javascript (browser builds in /browser/), can be used with elasticsearch.js.
Working code snippets where each step builds on the previous ones.
// app and authentication configurations
const HOSTNAME = "scalr.api.appbase.io"
const APPNAME = "createnewtestapp01"
const USERNAME = "RIvfxo1u1"
const PASSWORD = "dee8ee52-8b75-4b5b-be4f-9df3c364f59f"
// Add data into our ES "app index"
var elasticsearch = require('elasticsearch')
var client = new elasticsearch.Client({
host: 'https://'+USERNAME+":"+PASSWORD+"@"+HOSTNAME,
apiVersion: '1.6'
});
client.index({
index: APPNAME,
type: "product",
id: "1",
body: {
name: 'A green door',
price: 12.50,
tags: ['home', 'green'],
stores: ['Walmart', 'Target']
}
}, function(err, res) {
if (!err)
console.log(res);
});
var appbase = require('appbase-js')
var streamingClient = appbase.newClient({
url: 'https://'+HOSTNAME,
appname: APPNAME,
username: USERNAME,
password: PASSWORD
});
streamingClient.streamDocument({
type: 'product',
id: '1'
}).on('data', function(res) {
// client would emit "data" event every time there is a document update.
console.log(res)
}).on('error', function(err) {
console.log(err)
return
})
{ _index: 'app`248',
_type: 'product',
_id: '1',
_version: 4,
found: true,
_source:
{ name: 'A green door',
price: 12.5,
tags: [ 'home', 'green' ],
stores: [ 'Walmart', 'Target' ] } }
streamDocument() returns a stream.Readable
object, which can be conveniently listened via the 'on("data")' event listener. Check out the get_test.js where we make an update to the document and see it stream.
While streaming documents is straightforward, streaming queries touch the entire breadth of ElasticSearch Query DSL - boolean, regex, geo, fuzzy to name a few. We will stream the results of a simple match_all
query on the product
type:
streamingClient.streamSearch({
type: 'product',
body: {
query: {
match_all: {}
}
}
}).on('data', function(res, err) {
console.log(res);
}).on('error', function(err) {
console.log("caught a stream error", err)
return
})
{ took: 1,
timed_out: false,
_shards: { total: 1, successful: 1, failed: 0 },
hits:
{ total: 4,
max_score: 1,
hits: [ [Object], [Object], [Object], [Object] ] } }
streamSearch() also returns a stream.Readable
object, which can be conveniently listened via the 'on("data")' event listener. Check out the search_test.js where we make an update that matches the query and see it stream.
Returns a client
object on which streaming requests can be performed.
args - A set of key/value pairs that configures the ElasticSearch Index
url: "https://scalr.api.appbase.io"
appname: App name (equivalent to an ElasticSearch Index)
username: App's username
password: App's password key
Get all the document changes as a stream. Returns a stream.Readable
object.
args - A set of key/value pairs that makes the document URL
type: ElasticSearch Type, a string
id: Valid Document ID
Get all the query results as a stream. Returns a stream.Readable
object.
args - A set of key/value pairs that makes the document URL
type: ElasticSearch Type, a string
body: A JSON Query Body (Any query matching the ElasticSearch Query DSL)
FAQs
Appbase.io streaming client lib for Javascript
The npm package appbase-js receives a total of 3,748 weekly downloads. As such, appbase-js popularity was classified as popular.
We found that appbase-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.