{
  "source": "doc/api/https.md",
  "modules": [
    {
      "textRaw": "HTTPS",
      "name": "https",
      "introduced_in": "v0.10.0",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a\nseparate module.</p>\n",
      "classes": [
        {
          "textRaw": "Class: https.Agent",
          "type": "class",
          "name": "https.Agent",
          "meta": {
            "added": [
              "v0.4.5"
            ],
            "changes": []
          },
          "desc": "<p>An Agent object for HTTPS similar to <a href=\"http.html#http_class_http_agent\"><code>http.Agent</code></a>.  See <a href=\"#https_https_request_options_callback\"><code>https.request()</code></a>\nfor more information.</p>\n"
        },
        {
          "textRaw": "Class: https.Server",
          "type": "class",
          "name": "https.Server",
          "meta": {
            "added": [
              "v0.3.4"
            ],
            "changes": []
          },
          "desc": "<p>This class is a subclass of <code>tls.Server</code> and emits events same as\n<a href=\"http.html#http_class_http_server\"><code>http.Server</code></a>. See <a href=\"http.html#http_class_http_server\"><code>http.Server</code></a> for more information.</p>\n",
          "methods": [
            {
              "textRaw": "server.close([callback])",
              "type": "method",
              "name": "close",
              "meta": {
                "added": [
                  "v0.1.90"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`callback` {Function} ",
                      "name": "callback",
                      "type": "Function",
                      "optional": true
                    }
                  ]
                },
                {
                  "params": [
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"http.html#http_server_close_callback\"><code>server.close()</code></a> from the HTTP module for details.</p>\n"
            },
            {
              "textRaw": "server.listen()",
              "type": "method",
              "name": "listen",
              "desc": "<p>Starts the HTTPS server listening for encrypted connections.\nThis method is identical to <a href=\"net.html#net_server_listen\"><code>server.listen()</code></a> from <a href=\"net.html#net_class_net_server\"><code>net.Server</code></a>.</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "server.setTimeout([msecs][, callback])",
              "type": "method",
              "name": "setTimeout",
              "meta": {
                "added": [
                  "v0.11.2"
                ],
                "changes": []
              },
              "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": "<p>See <a href=\"http.html#http_server_settimeout_msecs_callback\"><code>http.Server#setTimeout()</code></a>.</p>\n"
            }
          ],
          "properties": [
            {
              "textRaw": "`timeout` {number} Defaults to 120000 (2 minutes). ",
              "type": "number",
              "name": "timeout",
              "meta": {
                "added": [
                  "v0.11.2"
                ],
                "changes": []
              },
              "desc": "<p>See <a href=\"http.html#http_server_timeout\"><code>http.Server#timeout</code></a>.</p>\n",
              "shortDesc": "Defaults to 120000 (2 minutes)."
            },
            {
              "textRaw": "`keepAliveTimeout` {number} Defaults to 5000 (5 seconds). ",
              "type": "number",
              "name": "keepAliveTimeout",
              "meta": {
                "added": [
                  "v8.0.0"
                ],
                "changes": []
              },
              "desc": "<p>See <a href=\"http.html#http_server_keepalivetimeout\"><code>http.Server#keepAliveTimeout</code></a>.</p>\n",
              "shortDesc": "Defaults to 5000 (5 seconds)."
            }
          ]
        }
      ],
      "methods": [
        {
          "textRaw": "https.createServer([options][, requestListener])",
          "type": "method",
          "name": "createServer",
          "meta": {
            "added": [
              "v0.3.4"
            ],
            "changes": []
          },
          "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()`][].",
                  "optional": true
                },
                {
                  "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",
                  "optional": true
                },
                {
                  "name": "requestListener",
                  "optional": true
                }
              ]
            }
          ],
          "desc": "<p>Example:</p>\n<pre><code class=\"lang-js\">// curl -k https://localhost:8000/\nconst https = require(&#39;https&#39;);\nconst fs = require(&#39;fs&#39;);\n\nconst options = {\n  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),\n  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;)\n};\n\nhttps.createServer(options, (req, res) =&gt; {\n  res.writeHead(200);\n  res.end(&#39;hello world\\n&#39;);\n}).listen(8000);\n</code></pre>\n<p>Or</p>\n<pre><code class=\"lang-js\">const https = require(&#39;https&#39;);\nconst fs = require(&#39;fs&#39;);\n\nconst options = {\n  pfx: fs.readFileSync(&#39;test/fixtures/test_cert.pfx&#39;),\n  passphrase: &#39;sample&#39;\n};\n\nhttps.createServer(options, (req, res) =&gt; {\n  res.writeHead(200);\n  res.end(&#39;hello world\\n&#39;);\n}).listen(8000);\n</code></pre>\n"
        },
        {
          "textRaw": "https.get(options[, callback])",
          "type": "method",
          "name": "get",
          "meta": {
            "added": [
              "v0.3.6"
            ],
            "changes": [
              {
                "version": "v7.5.0",
                "pr-url": "https://github.com/nodejs/node/pull/10638",
                "description": "The `options` parameter can be a WHATWG `URL` object."
              }
            ]
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`options` {Object | string | URL} Accepts the same `options` as [`https.request()`][], with the `method` always set to `GET`. ",
                  "name": "options",
                  "type": "Object | string | URL",
                  "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": "<p>Like <a href=\"http.html#http_http_get_options_callback\"><code>http.get()</code></a> but for HTTPS.</p>\n<p><code>options</code> can be an object, a string, or a <a href=\"url.html#url_the_whatwg_url_api\"><code>URL</code></a> object. If <code>options</code> is a\nstring, it is automatically parsed with <a href=\"url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost\"><code>url.parse()</code></a>. If it is a <a href=\"url.html#url_the_whatwg_url_api\"><code>URL</code></a>\nobject, it will be automatically converted to an ordinary <code>options</code> object.</p>\n<p>Example:</p>\n<pre><code class=\"lang-js\">const https = require(&#39;https&#39;);\n\nhttps.get(&#39;https://encrypted.google.com/&#39;, (res) =&gt; {\n  console.log(&#39;statusCode:&#39;, res.statusCode);\n  console.log(&#39;headers:&#39;, res.headers);\n\n  res.on(&#39;data&#39;, (d) =&gt; {\n    process.stdout.write(d);\n  });\n\n}).on(&#39;error&#39;, (e) =&gt; {\n  console.error(e);\n});\n</code></pre>\n"
        },
        {
          "textRaw": "https.request(options[, callback])",
          "type": "method",
          "name": "request",
          "meta": {
            "added": [
              "v0.3.6"
            ],
            "changes": [
              {
                "version": "v9.3.0",
                "pr-url": "https://github.com/nodejs/node/pull/14903",
                "description": "The `options` parameter can now include `clientCertEngine`."
              },
              {
                "version": "v7.5.0",
                "pr-url": "https://github.com/nodejs/node/pull/10638",
                "description": "The `options` parameter can be a WHATWG `URL` object."
              }
            ]
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`options` {Object | string | URL} 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 | URL",
                  "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": "<p>Makes a request to a secure web server.</p>\n<p>The following additional <code>options</code> from <a href=\"tls.html#tls_tls_connect_options_callback\"><code>tls.connect()</code></a> are also accepted\nwhen using a custom <a href=\"#https_class_https_agent\"><code>Agent</code></a>: <code>ca</code>, <code>cert</code>, <code>ciphers</code>, <code>clientCertEngine</code>,\n<code>key</code>, <code>passphrase</code>, <code>pfx</code>, <code>rejectUnauthorized</code>, <code>secureProtocol</code>, <code>servername</code></p>\n<p><code>options</code> can be an object, a string, or a <a href=\"url.html#url_the_whatwg_url_api\"><code>URL</code></a> object. If <code>options</code> is a\nstring, it is automatically parsed with <a href=\"url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost\"><code>url.parse()</code></a>. If it is a <a href=\"url.html#url_the_whatwg_url_api\"><code>URL</code></a>\nobject, it will be automatically converted to an ordinary <code>options</code> object.</p>\n<p>Example:</p>\n<pre><code class=\"lang-js\">const https = require(&#39;https&#39;);\n\nconst options = {\n  hostname: &#39;encrypted.google.com&#39;,\n  port: 443,\n  path: &#39;/&#39;,\n  method: &#39;GET&#39;\n};\n\nconst req = https.request(options, (res) =&gt; {\n  console.log(&#39;statusCode:&#39;, res.statusCode);\n  console.log(&#39;headers:&#39;, res.headers);\n\n  res.on(&#39;data&#39;, (d) =&gt; {\n    process.stdout.write(d);\n  });\n});\n\nreq.on(&#39;error&#39;, (e) =&gt; {\n  console.error(e);\n});\nreq.end();\n</code></pre>\n<p>Example using options from <a href=\"tls.html#tls_tls_connect_options_callback\"><code>tls.connect()</code></a>:</p>\n<pre><code class=\"lang-js\">const options = {\n  hostname: &#39;encrypted.google.com&#39;,\n  port: 443,\n  path: &#39;/&#39;,\n  method: &#39;GET&#39;,\n  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),\n  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;)\n};\noptions.agent = new https.Agent(options);\n\nconst req = https.request(options, (res) =&gt; {\n  // ...\n});\n</code></pre>\n<p>Alternatively, opt out of connection pooling by not using an <code>Agent</code>.</p>\n<p>Example:</p>\n<pre><code class=\"lang-js\">const options = {\n  hostname: &#39;encrypted.google.com&#39;,\n  port: 443,\n  path: &#39;/&#39;,\n  method: &#39;GET&#39;,\n  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),\n  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;),\n  agent: false\n};\n\nconst req = https.request(options, (res) =&gt; {\n  // ...\n});\n</code></pre>\n<p>Example using a <a href=\"url.html#url_the_whatwg_url_api\"><code>URL</code></a> as <code>options</code>:</p>\n<pre><code class=\"lang-js\">const { URL } = require(&#39;url&#39;);\n\nconst options = new URL(&#39;https://abc:xyz@example.com&#39;);\n\nconst req = https.request(options, (res) =&gt; {\n  // ...\n});\n</code></pre>\n"
        }
      ],
      "properties": [
        {
          "textRaw": "https.globalAgent",
          "name": "globalAgent",
          "meta": {
            "added": [
              "v0.5.9"
            ],
            "changes": []
          },
          "desc": "<p>Global instance of <a href=\"#https_class_https_agent\"><code>https.Agent</code></a> for all HTTPS client requests.</p>\n"
        }
      ],
      "type": "module",
      "displayName": "HTTPS"
    }
  ]
}
