How to use routes from Express for HTTPS? How to use routes from Express for HTTPS? express express

How to use routes from Express for HTTPS?


Using the API docs for .listen on my own projects with similar need, and looking at your code, I think two quick changes should work:

1) add var http = require('http'); to the top with your other requires.

2) change the last two lines of the app to:

// START THE SERVER// =============================================================================http.createServer(app).listen(port);https.createServer(credentials, app).listen(443);

(If this works, you can also remove the reference to httpsServer.)


Truthfully, unless you have a very good reason not to I'd look at putting either a web server (NGINX) in front of your node app or a load balancer.

This helps in a number of ways, not the least of which being that you can terminate the HTTPS request there and let your node app not care.