npm package: @mobile-outfitters/node-networker
Description: A node.js library for managing network connections. Connect/disconnect from networks and view network interfaces.
Author: Darren McDowell & Noah Gaeta & Matt Stephens
Latest version: 1.3.5

# Node Networker

Node Networker is a Node.js wrapper for managing network interfaces across platforms. It provides a unified API for interacting with network interfaces and wifi networks on both Linux and Windows.

## Installation

To install node-networker, you can run the following commands:

yarn: `yarn add @mobile-outfitters/node-networker`
npm: `npm i @mobile-outfitters/node-networker`

## Electron Support

Currently, Electron does work with this package.

## Example Usage

Here's a simple example of how to use `node-networker`:

```typescript
import { networker, NetworkInterfaceType } from '@mobile-outfitters/node-networker';

const main = async () => {
    const nw = networker({});

    // get network interfaces
    const interfaces = await nw.listNetworkInterfaces();

    // Find what wifi network is currently connected
    const wifiInterface = interfaces.find((nwInterface) => nwInterface.interfaceType === NetworkInterfaceType.Wifi);
    console.log('My wifi network connected is: ', wifiInterface ? wifiInterface.networkName : 'None Found!');

    // Find ethernet interface and get the internet status
    const ethernetInterface = interfaces.find(
        (nwInterface) => nwInterface.interfaceType === NetworkInterfaceType.Ethernet
    );
    console.log(
        ethernetInterface
            ? `I have an ethernet network connected, internet status: '${ethernetInterface.internetStatus}`
            : 'I do not have an ethernet network connected!'
    );

    // get wifi networks
    const networks = await nw.listWifiNetworks();
    console.log(`I have these wifi networks available: ${networks}`);

    const internet = await nw.internetStatus();
    console.log(`I have an internet status of: ${internet}`);

    // connect to a wifi network
    await nw.connectWifi({ ssid: 'my-wifi-network', password: 'my-wifi-password' });
    console.log('I am now connected to my wifi network!');

    // disconnect from wifi
    await nw.disconnectWifi();
};

main();
```

## Typings

Node-networker provides TypeScript typings for all its exported functions and objects.
You can find these typings in [src/types.ts](src/types.ts).

## Windows

Node-networker uses a native Node addon for interacting with the Windows network API.
It supports the following windows versions:

-   Windows 8.1
-   Windows 10
-   Windows 11

The windows node-addon built using `node-gyp` and the source code can be found in the `src/_windows/addon/src` directory. The resulting `.node` binary is output to the `src/_windows/addon/output`.

## Linux

Node-networker uses nmcli to interact with the network interfaces. nmcli is a command-line interface for NetworkManager and is pre-installed on most Linux distributions.

## MacOS

Node-networker uses airport, ipconfig, and networksetup. The MacOS version is currently experimental and may not be fully reliable.

## Building

In order to build the project without re-building the windows binary
yarn: `yarn run build`
npm: `npm run build`

If you made changes to the windows addon
yarn: `yarn run build-windows-binary`
npm: `npm run build-windows-binary`

## Testing

Node-networker includes unit tests which mocks the outputs from either nmcli or the native node addon.
To run tests:
yarn: `yarn run test`
npm: `npm run test`