TCP

net.isIP()

Classifies an address literal as IPv4, IPv6 or neither. It does not resolve a hostname or prove that an address is reachable. Tested on Node.js 22.16.0. Example output (one line per entry): ["4 6 0"].

Formal Syntax & Structure

nodejs syntaxnodejs
net.isIP(input)

Parameters & Attributes

NameTypeDescription
inputstringAddress candidate.

Return Value

number

4, 6 or 0.

Working Example

Example Snippetnodejs
import { isIP } from 'node:net';console.log(isIP('127.0.0.1'), isIP('::1'), isIP('localhost'));
Node.js Reference