Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including m_jet with all npm packages installed. Try it out:

var mJet = require("m_jet")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

m_jet v1.1.2

full stack node framework

m_jet

Build Status

Full stack node js framework.

m_jet: a tool for prototyping websites and API's that supports re-connecting multiplexed websockets.

m_jet uses Routes, Shoe & Dataplex:

Routes

Please refer to routes documentation for its capabilities...

routes on github.

Dataplex

Data is sent via dataplex and named multiplexed websocket streams, in the browser and server. Dataplex behaves like any other stream, allowing you to pipe to and pipe from it. Check out dataplex's documentation for more usage examples.

dataplex on github.

install

npm install m_jet --save

example

var jet = require('m_jet').server();

jet.router.addRoute('/json/api', function (req, res) {
    jet.json(res, { a: 'demo!' });
});

jet.router.addRoute('/', function (req, res) {
    jet.render_html(res, 'index.html');
});

jet.router.addRoute('/wildcard/:id?', function (req, res, j) {
    if (j.params.id === 'summin') {
        res.end('<h1>wildcard route</h1>');
    }
});

jet.socket(function (plex) {
    plex.add('/demo', function () {
        var d = new Readable;
        d.push('1');
        d.push('2');
        d.push('3');
        d.push(null);
        return d;
    });
});

jet.start();

on the client.

var jet = require('m_jet').client();

jet(function (plex) {
    
    let demo = plex.open('/demo');
    
    demo.on('data', function (data) {
        console.log(data);
    });
});

client events

var jet = require('m_jet').client();

jet(function (plex, session) {
    
    let demo = plex.open('/demo');
    
    demo.on('data', function (data) {
        console.log(data);
    });

    session.on('connect', function () { console.log('connected!'); })
    session.on('disconnect', function () { console.log('client disconnected!'); })
    session.on('error', function (e) { console.log('an error has occured: ', e) })

    // cleanly exit this websocket session...

    session.destroy()

});

build with browserify...

browserify ./client.js -o public/bundle.js

include in the browser...

<script src="./bundle.js"></script>

todo

  1. CORS?
  2. middlewares / plugins / extendability?

contributions

  1. All contributions / abuse / ideas welcome!
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free