1.0.2 • Published 2 years ago
@bugsounet/nat-api v1.0.2
nat-api
Fast port mapping with UPnP in NodeJS.
This is a fork version of nat-api, and https://github.com/Voxelum/nat-api
This version is writed for MagicMirror and Gateway v2 application
Install
Required: NodeJS >= 10
npm install @bugsounet/nat-api
Usage
const { createUpnpClient } = require('@bugsounet/nat-api')
const client = await createUpnpClient()
// map 25565 to 25565 for 1 min:
await client.map({
description: "Mapped by @bugsounet/nat-api",
protocol: 'tcp',
public: 25565,
private: 25565,
ttl: 60 * 1000,
})
// Unmap port public and private port 25565 with TCP by default
await client.unmap({ public: 25565 })
// Get external Mapping
const mappings = await client.getMappings()
// see existed mappings
console.log(mappings)
// Get external IP
const ip = await client.externalIp()
// see external IP
console.log(ip)
// Destroy client
client.destroy()
API
See type definition in typescript.
Additional Information
License
MIT. Copyright (c) @bugsounet