Skip to content

extremeheat/node-basic-ipc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-basic-ipc

NPM version Build Status Gitpod ready-to-code

Node.js real-time client <-> server (between backend and browser) communication library for IPC.

Features:

  • Send and receive JSON objects or binary data
  • Send and receive messages in chunks
  • Request-response pattern

Install

npm install basic-ipc

Usage (Node.js)

Simple example of server and client communication using WebSocket:

const ipc = require('basic-ipc');
const server = ipc.createServer({
  ws: { port: 8091 }
})

server.once('listening', () => {
  const client = ipc.createClient({
    ws: { url: 'ws://localhost:8091' }
  })
  client.once('open', () => {
    client.sendMessage('hello', { world: '!' })
  })
})

server.on('join', async (client) => {
  client.receive('hello', (message) => {
    console.log('Received hello message:', message)
    server.close()
    client.close()
  })
})

Usage (Browser)

In the browser, you can only create clients. basic-ipc exposes a special browser API that only exports code relevant to the client side. You can access it by importing basic-ipc/browser:

const ipc = require('basic-ipc/browser');

API

See the type definitions in index.d.ts for more information.

License

MIT