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

razorframe

v1.0.21

Published

Empowering scalable, real-time web apps in Node.js

Downloads

35

Readme

#razorframe
Version
npm version Build Status

###Empowering scalable, real-time web apps in Node.js

###Visit us at: http://www.razorfra.me

##Table of Contents:

  1. Description
  2. Installation
  3. Usage: Server-Side Module
  4. Usage: Client-Side module
  5. Demo App
  6. Platform Support
  7. Dependencies
  8. Authors
  9. Feedback
  10. Support
  11. Contributions
  12. License

##Description
Razorframe is a Javascript library built on Node.js which enables developers to build a real-time client experience while maintaining scalable, async back-end operations.

Socket.io powers real-time client updates on the front-end, while Node clusters and event emitters in conjunction with a custom messaging queue process highly concurrent and asynchronous operations on the back-end.

We use a messaging queue, called razorframe, that intercepts incoming user interactions over a two-way socket channel. Those interactions are held in the queue only as long as the server needs before dequeuing. The dequeuing process then triggers an event that both updates the client UI and launches a back-end process such as a database write.

Our tests have shown this process keeps the client UI updating in sub 100ms "real-time" fashion at scale while maintaining accurate database writes.

##Installation Using npm:

$ npm i --save razorframe

##How to Use

###Hosted Redis server:
We have removed the hosted Redis server originally provided during initial rollout. In order to leverage concurrency with razorframe and ensure server -> client communication, be sure to instantiate a local or hosted Redis server for your application.

You can store your Redis reference in an environment variable, or fall back to a locally hosted instance (see below):

const REDIS_URL = process.env.REDIS_URL || { host: 'localhost', port: 6379 }

###Server-side module:

(1) Require razorframe
(2) Specify rzConfig object to set up server processes by declaring:

  • rzConfig.port: port where your server is listening.
  • rzConfig.cluster: true or false depending on whether you want to enable Node clusters.
    (Even though our config automatically accounts for 1 process if not specified, you'll still get better performance if you turn off Node clusters if you know you won't be using more than one CPU.)

(3) Specify dbConfig object to define your back-end callbacks

  • dbConfig.write: 'create' function for database.
  • dbConfig.show: 'read' function for database.
  • dbConfig.update: 'update' function for database.
  • dbConfig.delete: 'delete' function for databse.

(4) Initialize razorframe while passing in http (for your server) and the configurations

const rz = require('razorframe');

const rzConfig = {
  port: process.env.PORT || 3000,
  cluster: true
};

const dbConfig = {
  write: addToDb,
  show: showAll,
  update: null,
  delete: null,
};
 
rz.init(http, rzConfig, dbConfig);

###Client-side module: HTML
Import 2 libraries: socket.io and razorframe into your HTML.
Grab the client-side import file from our website razorfra.me or use the hosted link below:

<script src="/socket.io/socket.io.js"></script>
<script src="http://parkedwards.github.io/parkedwards.github.io/razorframe.js"></script>

Javascript
Contains 2 methods:

  1. rz.publish - publishes a data payload to a particular event and specifies a back-end callback
    Specify arguments:
  • contents: message data
  • function name (as a string): a back-end operation you want to perform as defined in dbConfig.
  • event name: name the event you can then subscribe to.
textForm.addEventListener('submit', (e) => {
  e.preventDefault();
  const contents = textInput.value;
  rz.publish(contents, 'write', 'chatMsg')
  textInput.value = '';
});
  1. rz.subscribe - listens for an event coming from the server
    Specify arguments:
  • event name: the event you want to listen for.
  • callback function: any function you want to call on the payload from the event.
rz.subscribe('dbOnLoad', (data) => {
  data.reverse().forEach(item => {
    node = document.createElement('LI');
    textNode = document.createTextNode(JSON.parse(item));
    node.appendChild(textNode);
    chatMsg.appendChild(node);
  });
});

Error Handling:
Razorframe enables error handling on the back-end if your database fails to query.
Within the error callback on your database controller, use the method:

if (err) rz.onError(MSG, 2);

where 'MSG' is the task being sent to the database and the second argument, in this case '2', specifies the number of attempts to do the query. Razorframe will re-enqueue the task 'n' number of times with a default of 2 total attempts. If the event fails to query after all attempts, a message is sent to the user that enqueued the event that the event has failed to write and will be dropped.

##Demo App Check out our demo app for more usage examples at: RZ-Demo

##Platform Node.js

##Dependencies Socket.io

##Authors
Travis Huff
Eddie Park
Michael Sotkin

##Feedback Click this Link to leave feeback. We want to hear from you! ⚡️

##Support
Tested in Chrome 55 & Node 6/7.
GitHub Issues: https://github.com/team-emt/razorframe/issues

##Contributions ❤️ Contributions welcome!
Please see out GitHub repo at: https://github.com/team-emt/razorframe

##License
MIT