TCP

net.isIPv4()

Checks IPv4 literal syntax. Use it for format checks only; authorization and network policies require additional validation. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false"].

Formal Syntax & Structure

nodejs syntaxnodejs
net.isIPv4(input)

Parameters & Attributes

NameTypeDescription
inputstringAddress candidate.

Return Value

boolean

Whether input is IPv4.

Working Example

Example Snippetnodejs
import { isIPv4 } from 'node:net';console.log(isIPv4('192.0.2.1'), isIPv4('192.0.2.256'));
Node.js Reference