A Node.js package for using UPnP
npm install upnpjs



Node.js package built for managing a router using UPnP.
bash
npm install upnpjs
`Install upnp CLI
`bash
# Use upnp -h to show help menu
npm install upnpjs -g
`#
Getting Started
Discover the Internet Gateway Device
`JavaScript
const upnp = require('upnpjs'); const igd = await upnp.discover();
`
And that's all there is to it. Follow the documentation bellow to see what can be done with the newly discovered Internet Gateway Device.#
InternetGatewayDevice
InternetGatewayDevice allows access to different services potentially allowed by the device
$3
Service action for mapping ports on the router
`JavaScript
await igd.addPortMapping({
ip: 192.168.0.4,
internalPort: 54321,
externalPort: 54321,
protocol: 'TCP', // Defaults to TCP
description: 'Example port map from 54321 -> 54321', // Defaults to empty string
enabled: false // Defaults to true
});
`
$3
Service action for removing port mappings on the router
`JavaScript
await igd.deletePortMapping({
externalPort: 12345,
protocol: 'UDP'
});
`
$3
Service action for retrieving external ip address
`JavaScript
const ip = await igd.getExternalIPAddress();
`
$3
Service action for listing all currently mapped ports on the router
`JavaScript
const list = await igd.getPortMappingList();
`
$3
Service action for remtrieving a single port map by index
`JavaScript
const portmap = await igd.getPortMapping(2);
``#
UPnP Architecture |
Service Template |
UPnP Background |
Internet Gateway Device
Code Samples