-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_connection.js
More file actions
34 lines (28 loc) · 920 Bytes
/
verify_connection.js
File metadata and controls
34 lines (28 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const https = require('https');
const url = 'https://ecombackend-vl7q.onrender.com/getAllProducts';
console.log(`Fetching products from: ${url}`);
https.get(url, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const jsonData = JSON.parse(data);
if (jsonData.success) {
console.log(`✅ Success! Fetched ${jsonData.data.length} products.`);
if (jsonData.data.length > 0) {
const prod = jsonData.data[0];
console.log(`Product Keys: ${Object.keys(prod).join(', ')}`);
console.log(`Quantity Value: ${prod.quantity}`);
}
} else {
console.log('❌ Failed: API returned success=false');
}
} catch (e) {
console.error('❌ Error parsing JSON:', e.message);
}
});
}).on('error', (err) => {
console.error('❌ Network Error:', err.message);
});