Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const http = require('http');
- var querystring = require('querystring');
- const { performance } = require('perf_hooks');
- const t1 = performance.now();
- var post_data = querystring.stringify({});
- // An object of options to indicate where to post to
- var post_options = {
- host: 'localhost',
- port: '3000',
- path: '/',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json;charset=utf-8',
- 'Content-Length': Buffer.byteLength(post_data),
- },
- };
- const post_req = http
- .request(post_options, (resp) => {
- resp.setEncoding('utf8');
- let data = '';
- // A chunk of data has been received.
- resp.on('data', (chunk) => {
- data += chunk;
- });
- resp.on('end', () => {
- const t2 = performance.now();
- console.log('duration', t2 - t1);
- console.log('on end', data);
- });
- })
- .on('error', (err) => {
- console.log('Error: ' + err.message);
- });
- post_req.write(post_data);
- post_req.end();
Advertisement
Add Comment
Please, Sign In to add comment