-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-http.js
More file actions
38 lines (29 loc) · 706 Bytes
/
Copy pathtest-http.js
File metadata and controls
38 lines (29 loc) · 706 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
const http = require('http');
const options = {
hostname: 'localhost',
port: 5000,
path: '/api/v1/books',
method: 'GET',
timeout: 5000
};
console.log('Testing server at http://localhost:5000/api/v1/books...');
const req = http.request(options, (res) => {
console.log(`Status Code: ${res.statusCode}`);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('Response received:');
console.log(data);
});
});
req.on('error', (error) => {
console.error('Error:', error.message);
console.error('Code:', error.code);
});
req.on('timeout', () => {
console.error('Request timed out');
req.destroy();
});
req.end();