Realtime-web library, based on express and

Usage no npm install needed!

<script type="module">
  import expressOi from '';


This node.js library seeks to combine express and into one cohesive library. This project started as a fork of express.oi. This README is a fork too.

Getting started

First install:

npm install express-oi

Then, simply replace this line of code


with this line of code


Your app should run just the same as before! express-oi is designed to be a superset of express and


Setting up the app
var express = require('express-oi');

var app = express();

app.set('env',process.env.NODE_ENV || 'development');

// Here we create http.Server instance and connect to our app
// DEBUG disabled if app env is not "development"
// or if DEBUG no longer needed in app development env
// app.http().io({debug:false});

// Pass in your express-session configuration
// Documentation here:
// Just config options, dep. "express-session" are included in express-oi
// includes session both to app and{
  secret: 'express-oi makes me happy',
  resave: false,
  saveUninitialized: true

express-oi routes
var messages = [];'messages', {
  // event: messages:list
  list: function(req, res) {

  // event: messages:add
  add: function(req, res) {
    // data is accessible from (just like req.body, req.query)
    var data =;

    // Or use req.param(key)
    var message = {
      text: req.param('text')



  // event: messages:remove
  remove: function(req, res) {
    // Or just send a status code

Forwarding express routes

Regular express routes can be forwarded to express-oi routes

  .get(function(req, res) {
    // Forward GET /messages to messages:list'messages:list');
  .post(function(req, res) {
    // Forward POST /messages to messages:add'messages:add');
  .delete(function(req, res) {
    // Forward DELETE /messages to messages:remove'messages:remove');
More API Examples
// express-oi routes'examples', {
  example: function(req, res) {

    // Respond to current request
         message: 'This is my response'

    // You can check if current request is a websocket
    if (req.isSocket) {

      // Emit event to current socket
      req.socket.emit('message', 'this is a test');

      // Emit event to all clients except sender
      req.socket.broadcast.emit('message', 'this is a test');

      // sending to all clients in 'game' room(channel) except sender'game').emit('message', 'nice game');

      // sending to individual socketid, socketid is like a room'message', 'for your eyes only');


    // sending to all clients, including sender'message', 'this is a test');

    // sending to all clients in 'game' room/channel, including sender'game').emit('message', 'cool game');


0.0.21 - Enable DEBUG for app development env 0.0.20 - Fix session in io.route middleware 0.0.19 and earlier - See express.oi


sticky-session integration or emulating it.