How to run Node.js http-server with SSL?

Sometimes, we want to run Node.js http-server with SSL.

In this article, we’ll look at how to run Node.js http-server with SSL.

How to run Node.js http-server with SSL?

To run Node.js http-server with SSL, we should run https-server with the certificate file path as one of the option values.

For instance, we create a certificate with

mkcert 0.0.0.0 localhost 127.0.0.1 ::1

to create a certificate with mkcert after changing into the project directory.

Then we rename 0.0.0.0+3-key.pem to key.pem and 0.0.0.0+3.pem to cert.pem.

Finally, we run the https-server with cert.pem with

http-server -S -C cert.pem -o

Conclusion

To run Node.js http-server with SSL, we should run https-server with the certificate file path as one of the option values.