Skip to content

Commit

Permalink
docs: add examples for internalIP and internalIPSync
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jan 13, 2022
1 parent b2202b6 commit ec2e320
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/api/internal-ip-sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# internalIPSync(family: "v4" | "v6")

Returns the internal IP address synchronously.

```js
const WebpackDevServer = require("webpack-dev-server");

const localIPv4 = WebpackDevServer.internalIPSync("v4");
const localIPv6 = WebpackDevServer.internalIPSync("v6");

console.log("Local IPv4 address:", localIPv4);
console.log("Local IPv6 address:", localIPv6);
```

Use the following command to run this example:

```console
node app.js
```

## What Should Happen

- The script should log your local IPv4 and IPv6 address.
9 changes: 9 additions & 0 deletions examples/api/internal-ip-sync/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

const WebpackDevServer = require("../../../lib/Server");

const localIPv4 = WebpackDevServer.internalIPSync("v4");
const localIPv6 = WebpackDevServer.internalIPSync("v6");

console.log("Local IPv4 address:", localIPv4);
console.log("Local IPv6 address:", localIPv6);
27 changes: 27 additions & 0 deletions examples/api/internal-ip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# internalIP(family: "v4" | "v6")

Returns the internal IP address asynchronously.

```js
const WebpackDevServer = require("webpack-dev-server");

const logInternalIPs = async () => {
const localIPv4 = await WebpackDevServer.internalIP("v4");
const localIPv6 = await WebpackDevServer.internalIP("v6");

console.log("Local IPv4 address:", localIPv4);
console.log("Local IPv6 address:", localIPv6);
};

logInternalIPs();
```

Use the following command to run this example:

```console
node app.js
```

## What Should Happen

- The script should log your local IPv4 and IPv6 address.
13 changes: 13 additions & 0 deletions examples/api/internal-ip/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

const WebpackDevServer = require("../../../lib/Server");

const logInternalIPs = async () => {
const localIPv4 = await WebpackDevServer.internalIP("v4");
const localIPv6 = await WebpackDevServer.internalIP("v6");

console.log("Local IPv4 address:", localIPv4);
console.log("Local IPv6 address:", localIPv6);
};

logInternalIPs();

0 comments on commit ec2e320

Please sign in to comment.