All Projects → capaj → Moonridge

capaj / Moonridge

Licence: mit
Mongo live query framework bootstrapped on socket.io-rpc and mongoosejs. Takes your mongoose models and allows for easy and elegant consumption over the network in your frontend app or in remote node process.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Moonridge

AmigoChat-Realtime-Chat-Application
AmigoChat is a responsive real-time chat application built on MERN Stack and Socket io.
Stars: ✭ 22 (-66.67%)
Mutual labels:  socket-io, realtime-database
Vynchronize
Watch videos with friends online with the new real time video synchronization platform
Stars: ✭ 1,072 (+1524.24%)
Mutual labels:  socket-io
Nativescript Plugin Firebase
🔥 NativeScript plugin for Firebase
Stars: ✭ 990 (+1400%)
Mutual labels:  realtime-database
Node Chat One To One
Node.js socket-io based one to one chat engine
Stars: ✭ 47 (-28.79%)
Mutual labels:  socket-io
Trycode
Open-source realtime collaborative code editor on Babel, NodeJS, AngularJS, Socket.io, ACE - http://trycode.pw
Stars: ✭ 38 (-42.42%)
Mutual labels:  socket-io
Speedy Im
基于uni-app与uni-socket.io的即时通讯项目。
Stars: ✭ 49 (-25.76%)
Mutual labels:  socket-io
Express Security
nodejs + express security and performance boilerplate.
Stars: ✭ 37 (-43.94%)
Mutual labels:  socket-io
Genal Chat
🐱‍🏍阿童木聊天室 nestjs+vue全栈聊天室 前后端分离 typescript一把梭
Stars: ✭ 1,105 (+1574.24%)
Mutual labels:  socket-io
Chatter
A chatting app using socket.io
Stars: ✭ 53 (-19.7%)
Mutual labels:  socket-io
Nodejs Socketio Chat App
MEAN Stack & Socket.IO Real-time Chat App | A MEAN stack based Real Time chat application
Stars: ✭ 45 (-31.82%)
Mutual labels:  socket-io
Phaser3template
heroku deployable webpacked phaser3 template with socket.io for multi or single player games
Stars: ✭ 44 (-33.33%)
Mutual labels:  socket-io
Ihealth app
App front-end of iHealth project ( a medical WebApp based on mui )
Stars: ✭ 41 (-37.88%)
Mutual labels:  socket-io
Firebase Admin Node
Firebase Admin Node.js SDK
Stars: ✭ 1,050 (+1490.91%)
Mutual labels:  realtime-database
Progress Bot
High-tech weaponized moe progress delivery bot for IRC, Discord, and web
Stars: ✭ 38 (-42.42%)
Mutual labels:  socket-io
Bombanauts
Bombanauts, inspired by the original Bomberman game, is a 3D multiplayer online battle arena (MOBA) game where players can throw bombs at each other, make boxes explode, and even other players!
Stars: ✭ 54 (-18.18%)
Mutual labels:  socket-io
Socket Io
基于Hyperf微服务协程框架开发的sokcet-io分布式系统
Stars: ✭ 38 (-42.42%)
Mutual labels:  socket-io
Chat Buy React
Client for beginners to learn, built with React / Redux / Node
Stars: ✭ 1,026 (+1454.55%)
Mutual labels:  socket-io
Clicker
📺 a web remote control for the players out there
Stars: ✭ 47 (-28.79%)
Mutual labels:  socket-io
Go Socket.io Client
socket.io client for golang
Stars: ✭ 62 (-6.06%)
Mutual labels:  socket-io
Tyloo Chat
vue + nestjs IM即时通讯聊天室(仿wechat)
Stars: ✭ 54 (-18.18%)
Mutual labels:  socket-io

Deprecated notice

I don't maintain this anymore, so use only if you're willing to fix bugs yourself.

Moonridge Build Status Dependency Status

NPM badge

isomorphic client side library and server framework, which brings Mongoose model to the browser(or over the network to other node process). Based on socket.io-rpc. Framework agnostic-usable with anything-let it be Angular, Aurelia, React or any other.

Probably the coolest feature is live queries. These are performance hungry, but Moonridge is caching live queries in memory, so that one query is being live checked only once. If 10000 users run the same query, the DB performance performs the same amount of operations as if one user was accessing it. So your DB should be under the same load no matter how many people use your web app(presuming they are not writing into the DB).

Install

npm i moonridge -S

How to use it?

Serverside API is quite straightforward, if still not sufficent, read source code of examples.

in smoke test folder(Angular|React|Aurelia),

Basic usage serverside

    var MR = require('moonridge')

	MR.connect("mongodb://localhost/moonridge_showcase") //MongoDB address is optional-you can connect as always with mongoose
	var mongoose = MR.mongoose
    var bookModel = MR.model('book', {  //mongoose schema definition
            name: String,
            author: String
        }, {
             schemaInit: function (schema) {
                // makes sure only one book per nameXauthor exists
                schema.index({ name: 1, author: 1 }, { unique: true, dropDups: true });
            }
        })
    ...
    var app = require('express')()
    var server = require('http').Server(app)
    //bookModel is an extended mongoose model, so if you know how to work with mongoose models, you'll be right at home
    MR.bootstrap(server) 
    app.use('/api', MR.baucis()) // gives your REST api for your DB in case you need it alongside to socket.io API
    server.listen(port, () => {
          app.emit('listening')
          console.log('started listening on ' + port, ' in ', env, new Date())
    })

On the CLIENT:

   	var Moonridge = require('moonridge-client')
	//Moonridge backend
	var mr = Moonridge({url: 'http://localhost:8080', hs: {query: 'nick=testUser'}})
	var fighterModel = mr.model('fighter')
	//live query
	var LQ = fighterModel.liveQuery().sort('health').exec()

	LQ.promise.then(function(){
	  LQ.result //has a result of the query-array or a number
	  //query is live now
	});
	//create a new entity
	fighterModel.create({name: 'Arya', health: 50}).then(function(created){
	  console.log('created a fighter: ', created)
	  //LQ.result now also contains Arya
	  created.health = 49
	  //update an entity
	  fighterModel.update(created).then(function () {
  	    //remove it from DB
  	    fighterModel.remove(created)
	  });
	});

Also you need to connect to your backend-just pass a simple object with url property like HERE.

The whole client side api for queries shadows the Mongoose query API.

Errorhandling

All server-client communication is done with socket.io-rpc-another project of mine, so errors are propagated for all server-side calls which return an error(or reject their promise). This is especially helpful with schema validation errors, where backend tells the frontend exactly what failed.

Supported browsers

Desktop

Internet Explorer 8+ - though it needs es5shim
Safari 4+
Google Chrome 4+
Firefox 4+
Opera 10.61+

Mobile

iPhone Safari
iPad Safari
Android WebKit
WebOs WebKit

Why not just a ported mongoosejs on the client side?

One could ask why not just port mongoosejs to the client side and let clients talk to mongo directly. While this would surely be an interesting project, Moonridge has features which would not be possible without a server instance(live querying, custom authorization/authentication). I think these features are worth it introducing a new framework to the backend.

How does live querying work in one paragraph

Every client liveQuery is serialized and sent via socket.io to backend. Backend parses it and constructs real mongoose query, which is immediately run(if it doesn't exist already in server memory). The return is sent back to client. Any change to a certain document (creation, deletion, update) is checked again for all in-memory queries. MongoDB checks just one recently changed document, not the whole query, so it should be pretty quick. If query is satisfied, the changed document is propagated to listening clients. And that is basically it.

But mongoDB doesn't have JOINs!

Yes I know and if you need joins, you better look for something else. Moonridge is tailored for web apps which do a lot of small and custom queries. Basically you would want to save any bit of bandwith and show pieces of data in your app as soon as possible, you are best served using Moonridge.

Production samples

I have few production apps running on moonrige, feel free to take a peek how moonridge is used:

Pull requests are welcome and same goes for issues! js-standard-style

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].