Get up and running with LowlaDB in minutes
We’ve put together a simple, self-contained demo application to show how LowlaDB applications work and to serve as a starting point for your own applications. The demo uses LowlaDB’s default Node.js-based syncer with its built-in adapter for the embedded database NeDB. If you have MongoDB or PostgreSQL available, it’s easy to switch the demo to use that instead, but we recommend starting with NeDB for your first install.
You’ll need
git clone https://github.com/lowla/lowladb-demo-node
cd lowladb-demo-node
npm install
cd todomvc
bower install
cd ..
node app.js
Open a browser to the page
* http://localhost:3000/index.html
This launches a basic Todo app, allowing you to create and delete todo actions, edit them and mark them complete. As you make changes in the browser, the modified data is synced in the background to the web application. To see this in action, open another browser window to the same page (or even open a different browser, if you have one available.) Changes that you make in one window automatically show up in all other windows.
When you create or edit a document, LowlaDB performs the following actions
You can find more information throughout the documentation, in particular in the sections on the adapter and syncer.
Switching to MongoDB is as simple as reconfiguring the Node.js server to use a different datastore for both the Syncer and Adapter. The following steps assume that you have MongoDB server running on your local machine and want to store your data in a database called lowladb
. To change those settings, simply modify the mongoUrl
below when creating the MongoDatastore instance.
npm install lowladb-node-mongo --save
--save
option updates your package.json
file to record the dependency on lowladb-node-mongo.app.js
file in a text editor.
var lowladb = require('lowladb-node');
var MongoDatastore = require('lowladb-node-mongo');
lowladb.configureRoutes(app, { io: io(server) });
var lowlaConfig = {
datastore: new MongoDatastore({ mongoUrl: 'mongodb://127.0.0.1/lowladb' }),
io: io(server)
};
lowladb.configureRoutes(app, lowlaConfig);
The demo app will now run as before, but all data for both the syncer and adapter is now stored in MongoDB. If you have the MongoDB shell available, you can browse the lowladb database to confirm that data is indeed syncing up from the clients.
While it is common, you don’t have to use the same datastore for both the syncer and adapter. For example, if your data is stored in an existing PostgreSQL database then you need to use the PostgreSQL datastore for the adapter. You may want to use a separate MongoDB instance for syncer data to avoid modifying your PostgreSQL schema.