Categories
JavaScript Answers

How to use a self signed certificate for a HTTPS Node.js server?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *