M
https.get
History
Added in: v0.3.6
v0.3.6
Introduced in: v0.10.0
v0.10.0
The
url parameter can now be passed along with a separate options object.v10.9.0
The
options parameter can be a WHATWG URL object.v7.5.0
https.get(url, options?, callback?): http.ClientRequest
Attributes
Accepts the same
options as
https.request(), with the method set to GET by default.callback:
FunctionReturns:
http.ClientRequestLike http.get() but for HTTPS.
options can be an object, a string, or a URL object. If options is a
string, it is automatically parsed with new URL(). If it is a URL
object, it will be automatically converted to an ordinary options object.
import { get } from 'node:https'; import process from 'node:process'; get('https://encrypted.google.com/', (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers); res.on('data', (d) => { process.stdout.write(d); }); }).on('error', (e) => { console.error(e); });
const https = require('node:https'); https.get('https://encrypted.google.com/', (res) => { console.log('statusCode:', res.statusCode); console.log('headers:', res.headers); res.on('data', (d) => { process.stdout.write(d); }); }).on('error', (e) => { console.error(e); });