net-connect

Make tcp connections with a convenient api

Usage no npm install needed!

<script type="module">
  import netConnect from 'https://cdn.skypack.dev/net-connect';
</script>

README

Build Status

net-connect

Make tcp connections with a convenient api.

Example

var connect = require('net-connect');

// port
var con = connect(1337);

// ":port"
var con = connect(':1337');

// "host:port"
var con = connect('1.2.3.4:1337');

// { host, port }
var con = connect({ host: '1.2.3.4', port: 1337 });

// { address, port }
// this is what you get from server.address()
var con = connect({ address: '1.2.3.4', port: 1337 });

Installation

$ npm install net-connect

API

connect(obj[, listener])

Create a tcp connection to the address specified by obj.

Optionally pass a listener fn to be called when the connection has been established.

connect.parse(obj)

Parse obj and return a { host, port } object. This is used internally by connect().

License

MIT