0

I have a small node program.

console.log("Program Started");
var http = require('http');

//Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {      
    console.log("Processing Request for URL" + request.url);
    response.writeHead(200, {"Content-Type": "text/html"});
    response.end("Hello World \n");
});

// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000); 
console.log("Program Ended");    

If I run this program on my MacBook and access the following URL, I see my Hello World message.

http://localhost:8000/

However, I'd like to have this URL responding to HTTPS connections as well.

https://localhost:8000/

How can I do this with NodeJS?

Can the native http library do this for me? Or will I need Express?

Alana Storm
  • 164,128
  • 91
  • 395
  • 599

1 Answers1

1

Yes you can simply do It via https module :

1 you will have to create certificats , you can follow this auto here for macOS

https://stackoverflow.com/a/42298344/8395557

nodeover
  • 301
  • 1
  • 2
  • 11