To use a self signed certificate for a HTTPS Node.js server, we set a few options.
For instance, we write
const options = {
host: "localhost",
port: 8000,
path: "/api/v1/test",
rejectUnauthorized: false,
requestCert: true,
agent: false,
};
https
.createServer(options, (req, res) => {
res.writeHead(200);
res.end("OK\n");
})
.listen(8000);
to set rejectUnauthorized
to false
, requestCert
to true
, and agent
to false
to allow self signed certificates to be used on the https server.