refactory
Backend-in-a-box that automatically create factories save your data persistently and listen in realtime to changes in your data. Refactory will create all the necessary tables, http routes, client javascript files, and creates listeners for changes in your models in order to push them to the client.
Setup
-
Install through npm
npm install refactory
Examples
Simple Example
Listen to changes in the messages
table and the users
table and create two factories for them.
Server Side
There are two ways to use reFactory on your server: 1. Through a simple CLI, or 2. A Node.js application
CLI
The CLI is the quickest way to get up an running with refactory. It will automatically start serving static files from where the command is currently running.
1. Start refactory
refactory --models=messages,users --port 8000
2. Setup refactory in your client code
Module
1. Require refactory
, express
and http
In your Node.js App, require refactory and add it as a middleware to express:
var express = ;var http = ;var refactory = ;
2. Instantiate express app and httpServer
Create an http server and pass it the express app
var app = ;var httpServer = http;
3. Add refactory as a middleware to express.
This is where all your http routes will be created. You must all pass the httpServer, so that the socket connection can listen in the same port as your http traffic. Apart from passing the httpServer, you must also pass a list of models that you will you use in the front-end.
app ; httpServer;
4. Setup refactory in your client code
Client Side
1. Include script in your html
<!-- Include a reference to the client-side javascript file -->
2. Create a factory for your model
angular ;
CLI Options
Option Name | Type | Default | Help |
---|---|---|---|
models |
array | Comma separated list of models you wish to make available | |
port |
number | 3000 | Port number in which refactory should listen for traffic |
public_dir |
string | ./ | Directory from which to server static assets |
route |
string | refactory | Route from which to server will server refactory http routes |
db_host |
string | localhost | Host for RethinkDB |
db_port |
number | 28015 | Port for RethinkDB |
db_name |
string | refactory | Name of database in RethinkDB |
Module Options
Option Name | Type | Default | Help |
---|---|---|---|
models |
array | Comma separated list of models you wish to make available | |
httpServer |
object | Instance of httpServer (http module) |
|
db_host |
string | localhost | Host for RethinkDB |
db_port |
number | 28015 | Port for RethinkDB |
db_name |
string | refactory | Name of database in RethinkDB |