A Node module written in Typescript that allows for json objects and direct responses to TCP messages. Based off of ExpressJS request handling.
A Node module written in Typescript that allows for responses to TCP messages in json format. Based off of ExpressJS request handling.
npm install net-respond
Here is an example of a simple server/client connection
import {send} from './net-respond';
let address = 'localhost:1337';
//Send any json object
send({msg: 'Here is some Pie'},address,(res)=>{
console.log('recieved:',res);
});import {serve} from './net-respond';
//listening on port 1337
serve(1337,(req)=>{
let noun = req.data.value.msg.split(' ').slice(-1);
console.log('recieved:',req.data);
console.log('sending:',`Thanks for the ${noun}`);
req.respond(`Thanks for the ${noun}`);
});sending: Here is some Pie
sending: recieved: { from: '::ffff:127.0.0.1', value: 'Thanks for the Pie' }
recieved: { from: null, to: 'localhost:1337', value: 'Here is some Pie' }
sending: Thanks for the Pie
Distributed under the MIT license.
