npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

refactory

v0.0.1

Published

Automatically create factories tied to your RethinkDB tables, that are listening in realtime to changes in your data.

Downloads

4

Readme

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

  1. Install RethinkDB

  2. 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 = require('express');
var http = require('http');
var refactory = require('refactory');

2. Instantiate express app and httpServer

Create an http server and pass it the express app

var app = express();
var httpServer = http.createServer(app);

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
  .use('/refactory', refactory({
    models: ['message', 'user'],
    httpServer: httpServer
  }))
  .use(express.static(__dirname + '/../client'));

httpServer.listen(3000);

4. Setup refactory in your client code

Client Side

1. Include script in your html

<html>
    <!-- Include a reference to the client-side javascript file -->
    <script src="/refactory/client.js"></script>
</html>

2. Create a factory for your model

angular.module('rethinkDBWorkshop.services', [])
  .factory('messageFactory', ['refactoryFactory', function (refactoryFactory) {
      return refactoryFactory({
          model: 'message'
      });
  }])
  .factory('userFactory', ['refactoryFactory', function (refactoryFactory) {
      return refactoryFactory({
          model: 'user'
      });
  }])
  .controller('MainController', ['messageFactory', function (messageFactory) {

    // Get the initial state of messages (might be an empty array)
    var messages = messageFactory();

    messages.forEach(function (row) {
      console.log(row);
    });

    // Get all documents
    messageFactory.get().then(function (messages) {
      console.log(messages);
    });

    // The collection of messages will be saved to the database, and then
    // added to the collection in the client
    messageFactory.insert({
      'name': 'jorge',
      'age': 99
    });

    // update document in database
    messageFactory.update({
      id: "bf91cf63-55a7-47bd-8c68-a2396738b34f"
      text: 'hello world!'
    });

    // Delete document in database
    messageFactory.delete({
      id: "bf91cf63-55a7-47bd-8c68-a2396738b34f"
    });

  }]);

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 |