Registry / http-networking / is-valid-http-url

is-valid-http-url

JSON →
library1.0.3jsnpmunverified

This package provides a focused utility function to determine if a given string adheres to the structural requirements of an HTTP or HTTPS URL. Currently at version 1.0.3, it is a stable, low-cadence library, primarily maintained for compatibility and reliability rather than frequent feature additions. Its core validation logic is built upon a robust regular expression initially developed by Diego Perini, which is well-regarded for its comprehensive coverage of various URL components. Unlike larger, more feature-rich URL parsing libraries, `is-valid-http-url` offers a lightweight and direct API specifically for string format validation, making it ideal for scenarios where only a quick check for valid HTTP/HTTPS URL syntax is needed without additional overhead.

npm install is-valid-http-url
INSTALL
IMPORT
SIG · IS-VALID-HTTP-URL
I
is-valid-http-url
http-networkingjavascriptv1.0.3
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

isUrl
✓ import isUrl from 'is-valid-http-url';
✗ import { isUrl } from 'is-valid-http-url';
The library exports a single function as its default. Use default import for ESM.
isUrl
✓ const isUrl = require('is-valid-http-url');
For CommonJS environments, the function is directly exported via `module.exports`.

This quickstart demonstrates how to import and use the `isUrl` function to validate various HTTP and HTTPS URL strings, showcasing both valid and invalid examples.

import isUrl from 'is-valid-http-url'; // Test cases for valid HTTP/HTTPS URLs console.log('Valid URLs:'); console.log(`http://example.com: ${isUrl('http://example.com')}`); console.log(`https://www.example.com/foo/?bar=baz&inga=42&quux: ${isUrl('https://www.example.com/foo/?bar=baz&inga=42&quux')}`); console.log(`http://localhost:3000: ${isUrl('http://localhost:3000')}`); console.log(`https://user:pass@host.com/path?query#hash: ${isUrl('https://user:pass@host.com/path?query#hash')}`); console.log('\nInvalid URLs:'); // Test cases for invalid URLs console.log(`example.com (missing scheme): ${isUrl('example.com')}`); console.log(`http://foo.bar?q=Spaces should be encoded: ${isUrl('http://foo.bar?q=Spaces should be encoded')}`); console.log(`ftp://example.com (non-http scheme): ${isUrl('ftp://example.com')}`); console.log(`invalid-url: ${isUrl('invalid-url')}`); console.log(` Note: This validator checks syntax, not if the URL actually exists or is reachable.`);
Debug
Known issues
gotchaThis library only validates the *format* of an HTTP/HTTPS URL string. It does not perform DNS lookups, check for server availability, or verify the existence of the resource at the given URL.
fix
If you require validation beyond format (e.g., checking if a URL is alive), you will need to integrate additional network request logic (e.g., using `fetch` or `axios`).
affects: >=1.0.0
gotchaThe validator is specifically designed for HTTP and HTTPS protocols. It will return `false` for URLs using other schemes like `ftp://`, `mailto:`, `file://`, etc., even if their format is otherwise correct for their respective schemes.
fix
For validating non-HTTP/HTTPS URLs, use a more general URL parsing library or a validator specific to that protocol.
affects: >=1.0.0
gotchaThe validation logic is based on a regular expression. While robust, extremely rare or highly unusual URL formats might not be perfectly covered. Ensure URLs conform to standard RFCs for best results.
fix
For critical applications with highly varied URL inputs, consider combining this with broader URL parsing libraries like Node.js's built-in `URL` class or `url-parse` for deeper structural analysis if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , is_valid_http_url_1.default) is not a function
Attempting to use a named import (`import { isUrl } from '...'`) for a package that provides a default export in an ESM context.
fix
Change the import statement to `import isUrl from 'is-valid-http-url';` for ESM environments.
TypeError: isUrl is not a function
Occurs when `require()` is used on a module that primarily expects ESM default imports, or if the imported name does not match the exported symbol.
fix
Ensure you are using `const isUrl = require('is-valid-http-url');` in CommonJS, or `import isUrl from 'is-valid-http-url';` in ESM, as the package provides a default function export.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
is-valid-http-url — npm install is-valid-http-url · libregistry