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

rtdb-api

v1.0.3

Published

RealTime Database

Downloads

11

Readme

RTDb-API

==========

The RealTime Database access with REST and Socket.IO

How does it work:

This server couples a RESTful (express) and Socket.IO API for real-time notifications. It is of course secure with a token authentication (JWS). It automatically exposes the tables in your database (except the user table) and allows you to select, insert, update and delete entities. It also supports uploading and downloading media to attach them to your entities. When you make a change on a table (insert, update, delete), connected clients are notified via Socket.IO.

Installation

Create a new nodejs project, add needed dependencies to your package.json:

{
  "name": "my_project",
  "engines": {
    "node": ">=6.9.1"
  },
  "dependencies": {
    "rtdb-api": "^1.0.0" 
  }
}
npm install rtdb-api

Server Usage

First you need to create a database with user table :

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(100) NOT NULL,
  `password` varchar(255) NOT NULL,
  `firstname` varchar(100) NOT NULL,
  `lastname` varchar(100) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

Next, create a configuration file in your node project (config.js):

module.exports = {
    secret: 'mysupersecretkey_tochange', // for jws
    host: 'localhost', // server ip listening
    port: 3000, // port
    mysql: { // mysql config
        host: 'localhost',
        port: 3306,
        user: 'user',
        password: 'pwd',
        database: 'database'
    },
    rootDir = __dirname // IMPORTANT !!!
};

Now in your express app (app.js) :

// Setup express server
var express     = require('express');
var app         = express();
var server      = require('http').Server(app);
// import your config
var config      = require('./config');
// initialize api
var api         = require('rtdb-api')(config, app, server);

// START SERVER
server.listen(config.port);
// ADD RTDB API ROUTES
app.use('/api', api);

And you can start your server:

node app.js

Javascript client

RTDb-API including a Javascript client. You can import it on your HTML front-end with socket.io (please include socket.io first):

<script src="/socket.io/socket.io.js"></script>
<script src="/rtdb/rtdb-client.js"></script>

In your personal script :

var db = new RTDb();
var repo = db.get('category');
db.login('[email protected]', 'pwd')
    .then(function(success) {
        if (success) {
            // init realtime
            repo.on('insert', function(data){})
                .on('update', function(data){})
                .on('delete', function(data){});
            
            // use find or findOne
            repo.find().then(function(data){});
            repo.findOne(1).then(function(data){});
            // your can insert, update or delete with:
            repo.insert({title: title}, function(err, result) {
                            if (err) throw err;
                            console.log('Api::Inserted', result);
                        });
            repo.update(1, {title: title}, function(err, result) {
                            if (err) throw err;
                            console.log('Api::Updated', result);
                        });
            repo.delete(1, function(err, result) {
                            if (err) throw err;
                            console.log('Api::Deleted', result);
                        });
        }
    });

Android client

I have so create a Android client (ContentProvider with Sync & Service using Socket.IO) You can find Sample App in sample folder.