Enabling HTTPS for Your Express App

I am gonna show you the usage of SSL certificates along with Express JS based application. Once you have your private key and certificate, using them in your app is easy.

Enabling HTTPS for Your Express App

http Server

Let’s revisit how we’ve been creating our http server:

https Server

Switching over to HTTPS is simple. Put your private key and SSL cert in a subdirectory called ssl. Then you just use the https module instead of http, and pass an options object along to the createServer method:

That’s it. Assuming you’re still running your server on port 3000, you can now connect to https://localhost:3000. If you try to connect to http://localhost:3000, it will simply time out.

As we’ve seen, it’s very easy to use HTTPS with Express, and for development, it will work fine. However, when you want to scale your site out to handle more traffic, you will want to use a proxy server such as Nginx. I will cover it in the next tutorial.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.