Background paper texture mobile
nodejsfetchdebugging

Cek URL File dengan Node Fetch

Mengecek status response dan content-type file dari URL menggunakan Node.js

Author avatar

Peter Shaan

May 28, 2026


0 Views

Command ini dipakai untuk cek apakah file dari URL bisa diakses atau tidak.

Biasanya berguna untuk debug image/file storage, baik dari domain public maupun service internal Kubernetes.

Cek URL Public

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))"

Cek URL Internal Kubernetes

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))"

Output yang Dicek

Command akan menampilkan:

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

Penjelasan

status HTTP status code dari response, misalnya 200, 404, atau 500.

content-type Jenis file yang dikembalikan server, misalnya image/jpeg, image/png, atau text/html.

ok Bernilai true kalau status response berada di range 200-299.

Catatan

Kalau ok: false, berarti request berhasil sampai server, tapi response-nya bukan status sukses.

Kalau muncul error di catch, biasanya ada masalah network, DNS, SSL, atau URL tidak bisa dijangkau dari environment tempat command dijalankan.


Back to Notes