{ "source": "doc/api/https.md", "modules": [ { "textRaw": "HTTPS", "name": "https", "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", "methods": [ { "textRaw": "server.setTimeout(msecs, callback)", "type": "method", "name": "setTimeout", "meta": { "added": [ "v0.11.2" ] }, "desc": "

See http.Server#setTimeout().

\n", "signatures": [ { "params": [ { "name": "msecs" }, { "name": "callback" } ] } ] } ], "properties": [ { "textRaw": "server.timeout", "name": "timeout", "meta": { "added": [ "v0.11.2" ] }, "desc": "

See http.Server#timeout.

\n" } ] } ], "methods": [ { "textRaw": "https.createServer(options[, requestListener])", "type": "method", "name": "createServer", "meta": { "added": [ "v0.3.4" ] }, "desc": "

Returns a new HTTPS web server object. The options is similar to\ntls.createServer(). The requestListener is a function which is\nautomatically added to the 'request' event.

\n

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" ] }, "desc": "

See http.close() for details.

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

See http.listen() for details.

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

See http.listen() for details.

\n", "signatures": [ { "params": [ { "name": "port" }, { "name": "host", "optional": true }, { "name": "backlog", "optional": true }, { "name": "callback", "optional": true } ] } ] } ], "signatures": [ { "params": [ { "name": "options" }, { "name": "requestListener", "optional": true } ] } ] }, { "textRaw": "https.get(options, callback)", "type": "method", "name": "get", "meta": { "added": [ "v0.3.6" ] }, "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", "signatures": [ { "params": [ { "name": "options" }, { "name": "callback" } ] } ] }, { "textRaw": "https.request(options, callback)", "type": "method", "name": "request", "meta": { "added": [ "v0.3.6" ] }, "desc": "

Makes a request to a secure web server.

\n

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

\n

All options from http.request() are valid.

\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

The options argument has the following options

\n\n

The following options from tls.connect() can also be specified:

\n\n

In order to specify these options, use a custom 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};\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", "signatures": [ { "params": [ { "name": "options" }, { "name": "callback" } ] } ] } ], "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" } ] }