hee

1.1.13 • Public • Published

(H)ttp (E)vent (E)mitter

(H)ttp (E)vent (E)mitter

Installing

npm i hee

Example

Client (client.html)

<!DOCTYPE html>
<html>
 
<body>
    <script type="text/javascript">
        var source = new EventSource("http://localhost:8080/");
        source.onmessage = function (e) {
            document.body.innerHTML += `${e.data} <br>`;
        };
    </script> 
</body>
 
</html>
 

Server (server.mjs)

import HttpEventEmitter from 'hee'
 
const hee = new HttpEventEmitter(8080)
 
hee.on('subscription', (params) => {
  console.log('New subscription', params)
})
 
hee.on('event', (params) => {
  console.log('New event', params)
})
 

Run

node --experimental-modules server.mjs

Hee is using experimental ECMAScript modules https://nodejs.org/api/esm.html

API

const hee = new HttpEventEmitter([PORT])

Events

hee.on("subscription", params)

Emitted when a new client GET a path to listen.

hee.on("event", params)

Emitted when a client POST to a path.

Params:

{ 
  path: '/namespace/id/1',
  id: 'ad5a71fc-abc7-4d92-a585-d56934047ce9',
  data: { payload: 'Hello World' } 
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.13
    1
    • latest

Version History

Package Sidebar

Install

npm i hee

Weekly Downloads

1

Version

1.1.13

License

MIT

Unpacked Size

25.4 kB

Total Files

15

Last publish

Collaborators

  • javisantos