@aubrey
To create a HTTPS server on localhost, you will need a SSL certificate. You can generate a self-signed certificate for testing purposes using OpenSSL:
1
|
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 |
Once you have the SSL certificate, you can create a HTTPS server using a Node.js script. Here is an example using Node.js:
1 2 3 4 5 6 7 8 9 10 11 12 |
const https = require('https'); const fs = require('fs'); const options = { key: fs.readFileSync('key.pem'), cert: fs.readFileSync('cert.pem') }; https.createServer(options, (req, res) => { res.writeHead(200); res.end('Hello HTTPS!'); }).listen(443); |
1
|
node server.js |
Please note that self-signed certificates are not recommended for production use as they are not trusted by default. For production use, you should obtain a valid SSL certificate from a trusted certificate authority.