Create your own https server and SSL certificate

To create https server and SSL certificate you need to create two files:

  1. Certificate file (usually named cert.pem)
  2. Private key file (usually named key.pem)

Create SSL

In your terminal, navigate to your server folder (wherever your main server .js file is located), and then type the following commands:

        openssl genrsa -out client-key.pem 2048
        openssl req -new -key client-key.pem -out client.csr
        openssl x509 -req -in client.csr -signkey client-key.pem -out client-cert.pem
        *(Found on Stack Overflow)
      

The first line creates a private key named "client-key.pem", and the third line creates the SSL certificate named client-cert.pem

Then you just tell express to create the https server with the two files we mentioned above. We used fs (fs.readFileSync) module to read the two files and store them inside an object. Example (found in server.js):

        var options = {
          cert: fs.readFileSync('client-cert.pem'),
          key: fs.readFileSync('client-key.pem')
        };

        var server = https.createServer(options, app);