https.createServer()

https.createServer(options[, requestListener])

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

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
const https = require('https');
const fs = require('fs');
 
const options = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
 
https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);

Or

1
2
3
4
5
6
7
8
9
10
11
const https = require('https');
const fs = require('fs');
 
const options = {
  pfx: fs.readFileSync('server.pfx')
};
 
https.createServer(options, (req, res) => {
  res.writeHead(200);
  res.end('hello world\n');
}).listen(8000);
doc_Nodejs
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.