{ "source": "doc/api/https.md", "modules": [ { "textRaw": "HTTPS", "name": "https", "introduced_in": "v0.10.0", "stability": 2, "stabilityText": "Stable", "desc": "

HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a\nseparate module.

\n", "classes": [ { "textRaw": "Class: https.Agent", "type": "class", "name": "https.Agent", "meta": { "added": [ "v0.4.5" ] }, "desc": "

An Agent object for HTTPS similar to http.Agent. See https.request()\nfor more information.

\n" }, { "textRaw": "Class: https.Server", "type": "class", "name": "https.Server", "meta": { "added": [ "v0.3.4" ] }, "desc": "

This class is a subclass of tls.Server and emits events same as\nhttp.Server. See http.Server for more information.

\n", "properties": [ { "textRaw": "`headersTimeout` {number} **Default:** `40000` ", "type": "number", "name": "headersTimeout", "desc": "

See http.Server#headersTimeout.

\n", "shortDesc": "**Default:** `40000`" }, { "textRaw": "`keepAliveTimeout` {number} Defaults to 5000 (5 seconds). ", "type": "number", "name": "keepAliveTimeout", "meta": { "added": [ "v6.17.0" ] }, "desc": "

See http.Server#keepAliveTimeout.

\n", "shortDesc": "Defaults to 5000 (5 seconds)." } ], "methods": [ { "textRaw": "server.setTimeout([msecs][, callback])", "type": "method", "name": "setTimeout", "meta": { "added": [ "v0.11.2" ] }, "signatures": [ { "params": [ { "textRaw": "`msecs` {number} Defaults to 120000 (2 minutes). ", "name": "msecs", "type": "number", "desc": "Defaults to 120000 (2 minutes).", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "msecs", "optional": true }, { "name": "callback", "optional": true } ] } ], "desc": "

See http.Server#setTimeout().

\n" }, { "textRaw": "server.timeout([msecs])", "type": "method", "name": "timeout", "meta": { "added": [ "v0.11.2" ] }, "signatures": [ { "params": [ { "textRaw": "`msecs` {number} Defaults to 120000 (2 minutes). ", "name": "msecs", "type": "number", "desc": "Defaults to 120000 (2 minutes).", "optional": true } ] }, { "params": [ { "name": "msecs", "optional": true } ] } ], "desc": "

See http.Server#timeout.

\n" } ] } ], "methods": [ { "textRaw": "https.createServer(options[, requestListener])", "type": "method", "name": "createServer", "meta": { "added": [ "v0.3.4" ] }, "signatures": [ { "params": [ { "textRaw": "`options` {Object} Accepts `options` from [`tls.createServer()`][] and [`tls.createSecureContext()`][]. ", "name": "options", "type": "Object", "desc": "Accepts `options` from [`tls.createServer()`][] and [`tls.createSecureContext()`][]." }, { "textRaw": "`requestListener` {Function} A listener to be added to the `request` event. ", "name": "requestListener", "type": "Function", "desc": "A listener to be added to the `request` event.", "optional": true } ] }, { "params": [ { "name": "options" }, { "name": "requestListener", "optional": true } ] } ], "desc": "

Example:

\n
// curl -k https://localhost:8000/\nconst https = require('https');\nconst fs = require('fs');\n\nconst options = {\n  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),\n  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')\n};\n\nhttps.createServer(options, (req, res) => {\n  res.writeHead(200);\n  res.end('hello world\\n');\n}).listen(8000);\n
\n

Or

\n
const https = require('https');\nconst fs = require('fs');\n\nconst options = {\n  pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),\n  passphrase: 'sample'\n};\n\nhttps.createServer(options, (req, res) => {\n  res.writeHead(200);\n  res.end('hello world\\n');\n}).listen(8000);\n
\n", "methods": [ { "textRaw": "server.close([callback])", "type": "method", "name": "close", "meta": { "added": [ "v0.1.90" ] }, "signatures": [ { "params": [ { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "callback", "optional": true } ] } ], "desc": "

See http.close() for details.

\n" }, { "textRaw": "server.listen(path[, callback])", "type": "method", "name": "listen", "signatures": [ { "params": [ { "textRaw": "`path` {string} ", "name": "path", "type": "string" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "path" }, { "name": "callback", "optional": true } ] } ], "desc": "

See http.listen() for details.

\n" }, { "textRaw": "server.listen([port][, host][, backlog][, callback])", "type": "method", "name": "listen", "signatures": [ { "params": [ { "textRaw": "`port` {number} ", "name": "port", "type": "number", "optional": true }, { "textRaw": "`hostname` {string} ", "name": "hostname", "type": "string", "optional": true }, { "textRaw": "`backlog` {number} ", "name": "backlog", "type": "number", "optional": true }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "port", "optional": true }, { "name": "host", "optional": true }, { "name": "backlog", "optional": true }, { "name": "callback", "optional": true } ] } ], "desc": "

See http.listen() for details.

\n" } ] }, { "textRaw": "https.get(options[, callback])", "type": "method", "name": "get", "meta": { "added": [ "v0.3.6" ] }, "signatures": [ { "params": [ { "textRaw": "`options` {Object | string} Accepts the same `options` as [`https.request()`][], with the `method` always set to `GET`. ", "name": "options", "type": "Object | string", "desc": "Accepts the same `options` as [`https.request()`][], with the `method` always set to `GET`." }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "options" }, { "name": "callback", "optional": true } ] } ], "desc": "

Like http.get() but for HTTPS.

\n

options can be an object or a string. If options is a string, it is\nautomatically parsed with url.parse().

\n

Example:

\n
const https = require('https');\n\nhttps.get('https://encrypted.google.com/', (res) => {\n  console.log('statusCode:', res.statusCode);\n  console.log('headers:', res.headers);\n\n  res.on('data', (d) => {\n    process.stdout.write(d);\n  });\n\n}).on('error', (e) => {\n  console.error(e);\n});\n
\n" }, { "textRaw": "https.request(options[, callback])", "type": "method", "name": "request", "meta": { "added": [ "v0.3.6" ] }, "signatures": [ { "params": [ { "textRaw": "`options` {Object | string} Accepts all `options` from [`http.request()`][], with some differences in default values: ", "options": [ { "textRaw": "`protocol` Defaults to `https:` ", "name": "protocol", "desc": "Defaults to `https:`" }, { "textRaw": "`port` Defaults to `443`. ", "name": "port", "desc": "Defaults to `443`." }, { "textRaw": "`agent` Defaults to `https.globalAgent`. ", "name": "agent", "desc": "Defaults to `https.globalAgent`." } ], "name": "options", "type": "Object | string", "desc": "Accepts all `options` from [`http.request()`][], with some differences in default values:" }, { "textRaw": "`callback` {Function} ", "name": "callback", "type": "Function", "optional": true } ] }, { "params": [ { "name": "options" }, { "name": "callback", "optional": true } ] } ], "desc": "

Makes a request to a secure web server.

\n

The following additional options from tls.connect() are also accepted when using a\n custom Agent:\n pfx, key, passphrase, cert, ca, ciphers, rejectUnauthorized, secureProtocol, servername

\n

options can be an object or a string. If options is a string, it is\nautomatically parsed with url.parse().

\n

Example:

\n
const https = require('https');\n\nconst options = {\n  hostname: 'encrypted.google.com',\n  port: 443,\n  path: '/',\n  method: 'GET'\n};\n\nconst req = https.request(options, (res) => {\n  console.log('statusCode:', res.statusCode);\n  console.log('headers:', res.headers);\n\n  res.on('data', (d) => {\n    process.stdout.write(d);\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(e);\n});\nreq.end();\n
\n

Example using options from tls.connect():

\n
const options = {\n  hostname: 'encrypted.google.com',\n  port: 443,\n  path: '/',\n  method: 'GET',\n  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),\n  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')\n};\noptions.agent = new https.Agent(options);\n\nconst req = https.request(options, (res) => {\n  // ...\n});\n
\n

Alternatively, opt out of connection pooling by not using an Agent.

\n

Example:

\n
const options = {\n  hostname: 'encrypted.google.com',\n  port: 443,\n  path: '/',\n  method: 'GET',\n  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),\n  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),\n  agent: false\n};\n\nconst req = https.request(options, (res) => {\n  // ...\n});\n
\n" } ], "properties": [ { "textRaw": "https.globalAgent", "name": "globalAgent", "meta": { "added": [ "v0.5.9" ] }, "desc": "

Global instance of https.Agent for all HTTPS client requests.

\n" } ], "type": "module", "displayName": "HTTPS" } ] }