AppbaseJS
JavaScript library for Appbase Appbase.io Current Version: 2.2.17
Get Appbase
Node: npm install appbasejs
Browser: https://cdn.appbase.io/2.0/appbase.js
Dev
Do npm install
inside the folder to install devDependencies.
Browser Build
Distribution build
npm run-script build
: creates ./dist/appbase.min.js
Test build
npm run-script test_build
: creates ./build/appbase.js this build exposes internal server methods, and allows running tests on them in the browser.
Testing
npm test
for node.
Goto /test/browser/index.html for browser tests. If there's a test build, it will also run tests on internal server methods as well, otherwise will run tests only on interface methods.
Play
Node:
Appbase = require('appbasejs');
Browser:
<script src="./dist/appbase.min.js"></script>
Put Credentials
Appbase.credentials('app','secret');
Appbase references
Now let's create two Appbase references under namespaces "user" and "tweets".
var userRef = Appbase.ns("user").v("andy");
var tweetRef = Appbase.ns("tweet").v(Appbase.uuid());
As seen here, one can optionally specify the reference name.
Working with Data
userRef.setData({
status: "sudo",
location: "Belo Horizonte, Brazil"
});
tweetRef.setData({
message: "Remember Red, hope is a good thing."
});
Now let's add the tweet as an edge to our user reference.
userRef.setEdge(tweetRef, 'tweeted');
Go real-time!
Listen to the changes on the user reference data properties and edges, to see the changes we have made so far.
userRef.on('properties', function(error, ref, userSnap) {
console.log(userSnap.properties().status);
console.log(userSnap.properties().location);
});
userRef.on('edge_added', function(error, edgeRef, eSnap) {
edgeRef.on('properties', function(error, ref, tweetSnap) {
console.log(tweetSnap.properties().message);
});
});
Full-text search
Appbase.ns('tweet').search({text:'hello', properties: ['message']},function(err, array) {
console.log(array);
})