1.0.0 • Published 6 years ago

net-respond v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

net-respond

A Node module written in Typescript that allows for json objects and direct responses to TCP messages. Based off of ExpressJS request handling.

npm version

A Node module written in Typescript that allows for responses to TCP messages in json format. Based off of ExpressJS request handling.

Install

npm install

npm install net-respond

Usage example

Here is an example of a simple server/client connection

Client

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);
});

Server

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}`);
});

Client output

sending: Here is some Pie
sending: recieved: { from: '::ffff:127.0.0.1', value: 'Thanks for the Pie' }

Server output

recieved: { from: null, to: 'localhost:1337', value: 'Here is some Pie' }
sending: Thanks for the Pie

License

Distributed under the MIT license.