ERR_OUT_OF_RANGE

Node.js ErrorCore modulesRarerLast updated: June 28, 2026Tested on:Node.js v20 LTSNPM v10.2June 2026

A numeric value is outside the allowed boundaries.

ERR_OUT_OF_RANGE Quick Fix⏱️ Est. Fix Time: 3 minutes

Usually happens because:

  • Negative Sizes
  • Crypto Lengths
  • Out of Bounds Ports

🔍 Quick Checklist:

What is ERR_OUT_OF_RANGE?

The ERR_OUT_OF_RANGE error is thrown by Node.js when an input value (typically a number, index offset, or port) is outside the bounds of allowed arguments for a core API function.

Common Causes

  • Negative Sizes: Passing negative values to buffer allocation functions.
  • Crypto Lengths: Providing randomBytes lengths that exceed system allocation limits.
  • Out of Bounds Ports: Attempting to bind sockets to ports outside the 0 - 65535 range.
CauseFrequency
Negative Sizes⭐⭐⭐⭐⭐
Crypto Lengths⭐⭐⭐⭐
Out of Bounds Ports⭐⭐⭐

Common Mistakes

  • Passing user input directly to buffer allocations or crypto functions without validating the numbers bounds.

How to Fix

1Enforce Ranges: Validate number boundaries before invoking API calls.
2Sanitize Ports: Verify that server port parameters are valid unsigned 16-bit integers.

Framework-Specific Examples

Checking port variable ranges before binding the listener server.

Port range checks Example
const port = parseInt(process.env.PORT || '3000');
if (port < 0 || port > 65535) {
  throw new Error('Port variable out of range');
}
app.listen(port);

Server Configuration Examples

Checking port inputs.

Port range limits Config
# Handled at application layer

Best Practices

  • Implement schema constraints (e.g. Zod `.min()`, `.max()`) on API payload properties.

Frequently Asked Questions (FAQ)

Q: What triggers ERR_OUT_OF_RANGE?

It is thrown when a numeric parameter passed to a core Node.js function is outside the expected logical range (such as size constraints or negative array indexes).

Q: How does it differ from ERR_BUFFER_OUT_OF_BOUNDS?

ERR_OUT_OF_RANGE is a general error for function parameters. ERR_BUFFER_OUT_OF_BOUNDS is thrown specifically during buffer slice/read/write index overflows.

Q: Is this a RangeError?

Yes. It inherits from JavaScript's built-in `RangeError` class.

Q: How do I fix a port value out of range?

Ensure the port number parameter is an integer between 0 and 65535.

Still having this problem?

Didn't solve your problem?

SuggestRequest Error