You want the https
module. It acts just like the http
module, with a few differences that only matter when you want to check certs. See the node https docs for details.
In your example you can just replace require('http')
with require('https')
.
You probably don't want to worry about which protocol to use for every url you want to fetch, so you might want to look into a higher level library: the request library is very popular, although there are many others.