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

observerable

v0.0.4

Published

obSERVERable is a reactive alternative to Express (using rx.js)

Downloads

5

Readme

obSERVERable is a reactive alternative to Express (using rx.js)

Bringing the power of streams to the server

I love node.js and Express but I also love reactive programming. Express is a visionary in many ways but it is not a native fit to my reactive programming style..
obSERVERable is a server which allows you to program reactive (native) api (and applications of course).

With Express we are used to define an api like this:

var express = require('express')
var app = express()

app.get('/about', function (req, res) {
  res.send('about')
})

With obSERVERable you do stuff reactive:

const Observerable = require('../../lib/Observerable')();
const visualV8 = require('visualv8')();

//define application
Observerable.start(8080, 'localhost')
    .static('www')//static content folder
    .filter(require('./filters/Csrf'))//your own middlewares
    .filter(require('./filters/RequestLog'))//your own middlewares
    .module('/users', require('./modules/usersModule'))//module developed
    .module('/login', require('./modules/loginModule'));//module developed

//a module you develop
const UsersModule = function(module){
    
    //cool reactive rest resources composition
    module
        .get('/')//returns observable for '/' path
        .subscribe(request=>{
            Rx.Observable.zip(//aggragation of api resources 
                RxHttpRequest.get('http://localhost:8080/www/data/users.json').map(r=>JSON.parse(r.body)),
                RxHttpRequest.get('http://localhost:8080/www/data/orders.json').map(r=>JSON.parse(r.body))
            ).subscribe(zipResult=>{
                var users = zipResult[0],
                    orders = zipResult[1];
                request
                    .json(200, {users: users, orders: orders})
                    .subscribe();
            });
        }); 

    //simple loop iof data
    module.post('/new')
        .flatMap(request=>request.json(200, request.body))
        .subscribe(request=>{
            lastReturn=>{},
            err=>request
                    .json(500, err)
                    .subscribe()
        });  

    //database integration
    //using rx-mongodb a reactive mongodb libarary based on rxjs
     module.post('/save')//returns observable for '/save' path gor POST
        .subscribe(request=>{
            rxMongodb
                .connect(connectionString) 
                .flatMap(db=>rxMongodb.insert(collectionName, request.body))
                .flatMap(insertResult=>request.json(200, insertResult))
                .flatMap(response=>rxMongodb.close())
                .subscribe(
                    lastReturn=>{},
                    err=>request
                            .json(500, err)
                            .subscribe()
                );
        });
    
}

module.exports = UsersModule;

Installation

npm install observerable

Features

* Reactive stream based, you get a stream not request response
* Module based development
* Application level filters (like express middleware)
* Session Management
* Cookie Management
* More to come..

Install & run the sample application (usage demo)

cd examples
npm install
npm start

Then access http://localhost:8080

create server

const Observerable = require('observerable')();

Observerable.start(8080, 'localhost')//configure and start your server
    .static('www')//serve static files from a directory of you choosing
    .filter(require('./filters/Csrf'))//register application level filters (like Express middleware) that you write
    .filter(require('./filters/RequestLog'))
    .module('/users', require('./modules/UsersModule'));//register api modules that you define

program modules

modules expose streams by http verb (get and post) and routes

const UsersModule = function(module){
    
    module.get('/details/info')//listens to get requests on http://<domain>:<port>/users/info?id=1
        .flatMap(request=>request.json(200, request.params))//return querystring params sent (loop)
        .subscribe(request=>{
            lastReturn=>{},
            err=>request
                    .json(500, err)
                    .subscribe()
        });

    module.post('/auth')//listens to post requests on http://<domain>:<port>/users/auth
        .flatMap(request=>request.json(200, request.body))//return body data sent (loop)
        .subscribe(request=>{
            lastReturn=>{},
            err=>request
                    .json(500, err)
                    .subscribe()
        });
}

module.exports = UsersModule;