{ "source": "doc/api/https.markdown", "modules": [ { "textRaw": "HTTPS", "name": "https", "stability": 3, "stabilityText": "Stable", "desc": "

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

\n", "classes": [ { "textRaw": "Class: https.Server", "type": "class", "name": "https.Server", "desc": "

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

\n" }, { "textRaw": "Class: https.Agent", "type": "class", "name": "https.Agent", "desc": "

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

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

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

\n

Example:\n\n

\n
// curl -k https://localhost:8000/\nvar https = require('https');\nvar fs = require('fs');\n\nvar 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, function (req, res) {\n  res.writeHead(200);\n  res.end("hello world\\n");\n}).listen(8000);
\n

Or\n\n

\n
var https = require('https');\nvar fs = require('fs');\n\nvar options = {\n  pfx: fs.readFileSync('server.pfx')\n};\n\nhttps.createServer(options, function (req, res) {\n  res.writeHead(200);\n  res.end("hello world\\n");\n}).listen(8000);
\n", "methods": [ { "textRaw": "server.listen(path, [callback])", "type": "method", "name": "listen", "desc": "

See [http.listen()][] for details.\n\n

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

See [http.listen()][] for details.\n\n

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

See [http.close()][] for details.\n\n

\n", "signatures": [ { "params": [ { "name": "callback", "optional": true } ] } ] } ], "signatures": [ { "params": [ { "name": "options" }, { "name": "requestListener", "optional": true } ] } ] }, { "textRaw": "https.request(options, callback)", "type": "method", "name": "request", "desc": "

Makes a request to a secure web server.\n\n

\n

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

\n

All options from [http.request()][] are valid.\n\n

\n

Example:\n\n

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

The options argument has the following options\n\n

\n\n

The following options from [tls.connect()][] can also be specified. However, a\n[globalAgent][] silently ignores these.\n\n

\n\n

In order to specify these options, use a custom Agent.\n\n

\n

Example:\n\n

\n
var 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\nvar req = https.request(options, function(res) {\n  ...\n}
\n

Or does not use an Agent.\n\n

\n

Example:\n\n

\n
var 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\nvar req = https.request(options, function(res) {\n  ...\n}
\n", "signatures": [ { "params": [ { "name": "options" }, { "name": "callback" } ] } ] }, { "textRaw": "https.get(options, callback)", "type": "method", "name": "get", "desc": "

Like http.get() but for HTTPS.\n\n

\n

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

\n

Example:\n\n

\n
var https = require('https');\n\nhttps.get('https://encrypted.google.com/', function(res) {\n  console.log("statusCode: ", res.statusCode);\n  console.log("headers: ", res.headers);\n\n  res.on('data', function(d) {\n    process.stdout.write(d);\n  });\n\n}).on('error', function(e) {\n  console.error(e);\n});
\n", "signatures": [ { "params": [ { "name": "options" }, { "name": "callback" } ] } ] } ], "properties": [ { "textRaw": "https.globalAgent", "name": "globalAgent", "desc": "

Global instance of [https.Agent][] for all HTTPS client requests.\n\n

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