nodejs – https and selfsigned certificate

In this article I will talk about nodejs and listening to a ssl (https) port. To make a selfsigned certificate execute the command below:

Remember that browsers will complain about an invalid certificate. For most browsrs you can add a security exception for the certificate.

Now we have to tell nodejs to make use of this certificate when starting the https server. We have to create an option object with two properties: ‘key’ and ‘cert’. When we create the https server we pass in this option object:

The complete code for a https server with nodejs is shown below

The pug template that is served:

Share

Leave a Reply

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