-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-connection.js
More file actions
41 lines (32 loc) · 842 Bytes
/
test-connection.js
File metadata and controls
41 lines (32 loc) · 842 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
35
36
37
38
39
40
41
// Simple test to check if server is accessible
const http = require('http');
function testConnection() {
console.log('Testing connection to localhost:5000...');
const options = {
hostname: 'localhost',
port: 5000,
path: '/',
method: 'GET',
timeout: 5000
};
const req = http.request(options, (res) => {
console.log(`Server responded with status: ${res.statusCode}`);
console.log(`Headers:`, res.headers);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('Response body:', data);
});
});
req.on('error', (error) => {
console.error('Connection error:', error.message);
});
req.on('timeout', () => {
console.error('Connection timeout');
req.destroy();
});
req.end();
}
testConnection();