Skip to content

A super-lightweight IPC (Inter-Process Communication) protocol over TCP socket.

License

Notifications You must be signed in to change notification settings

gongzhang/procbridge-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

procbridge-nodejs

ProcBridge is a super-lightweight IPC (Inter-Process Communication) protocol over TCP socket or Unix domain socket. It enables you to send and recieve JSON between processes easily. ProcBridge is much like a simplified version of HTTP protocol, but only transfer JSON values.

Please note that this repo is the Node.js implementation of ProcBridge protocol. You can find detailed introduction of ProcBridge protocol in the main repository: gongzhang/procbridge.

Installation

npm i procbridge

Example

Server Side:

const { Server } = require('procbridge')

const server = new Server('0.0.0.0', 8000, (method, args) => {
  // define remote methods:
  switch (method) {
    case 'echo':
      return args
    case 'sum':
      return args.reduce((sum, next) => { return sum + next })
    case 'err':
      throw new Error('an server error')
  }
})

server.start()

Client Side:

const { Client } = require('procbridge')
const client = new Client('127.0.0.1', 8000)

// call remote methods:
await client.request('echo', 123) // 123
await client.request('echo', ['a', 'b', 'c']) // ['a', 'b', 'c']
await client.request('sum', [1, 2, 3, 4]) // 10

About

A super-lightweight IPC (Inter-Process Communication) protocol over TCP socket.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •