gistlib
index.tsxconst readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question('Enter a URL: ', function (url) { const http = url.startsWith('https') ? require('https') : require('http'); http.get(url, (res) => { let data = ''; // A chunk of data has been received. res.on('data', (chunk) => { data += chunk; }); // The whole response has been received. Print out the result. res.on('end', () => { console.log(data); rl.close(); }); }).on('error', (err) => { console.error(`Error: ${err.message}`); rl.close(); }); }); 650 chars30 lines
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.question('Enter a URL: ', function (url) { const http = url.startsWith('https') ? require('https') : require('http'); http.get(url, (res) => { let data = ''; // A chunk of data has been received. res.on('data', (chunk) => { data += chunk; }); // The whole response has been received. Print out the result. res.on('end', () => { console.log(data); rl.close(); }); }).on('error', (err) => { console.error(`Error: ${err.message}`); rl.close(); }); });
gistlibby LogSnag