Background paper texture mobile
nodejsfetchdebugging

Check File URL with Node Fetch

Checking response status and file content-type from a URL using Node.js

Author avatar

Peter Shaan

May 28, 2026


0 Views

This command is used to check whether a file from a URL is accessible or not. It's typically useful for debugging image/file storage, whether from a public domain or internal Kubernetes service.

Check Public URL

node -e "fetch('https://example.com/storage/image.jpg').then(async r => { console.log('status:', r.status);
console.log('content-type:', r.headers.get('content-type')); console.log('ok:', r.ok); }).catch(e => console.error(e))"

Check Internal Kubernetes URL

node -e "fetch('http://service-name.namespace.svc.cluster.local/storage/image.jpg').then(async r =>
{ console.log('status:', r.status); console.log('content-type:', r.headers.get('content-type')); console.log('ok:',
r.ok); }).catch(e => console.error(e))"
node -e "fetch('http://backend-service.namespace.svc.cluster.local/storage/image.png').then(async r =>
{ console.log('status:', r.status); console.log('content-type:', r.headers.get('content-type')); console.log('ok:',
r.ok); }).catch(e => console.error(e))"

Expected Output

The command will display:

status: 200
content-type: image/jpeg
ok: true

Explanation

status HTTP status code from the response, e.g. 200, 404, or 500.

content-type The file type returned by the server, e.g. image/jpeg, image/png, or text/html.

ok Returns true if the response status is in the 200-299 range.

Notes

If ok: false, it means the request successfully reached the server, but the response was not a success status. If an error appears in catch, there is usually a network, DNS, SSL, or URL reachability issue from the environment where the command is being run.


Back to Notes