0
const https = require('https');
const fs = require('fs');

const options = {
  key: fs.readFileSync('key.pem'),
  cert: fs.readFileSync('cert.pem')
};

https.createServer(options,(req,res)=>{

  console.log('https server start');
}).listen(8080,'localhost');

Dear every one, I tried make https server... and this code. But not working.

Before i make key.pem, cert.pem for localhost server

Like this code

openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > cert.pem

and this thing in the same folder

but not working like this enter image description here

Thank you and Regards.!

King in the world.
  • 357
  • 1
  • 3
  • 13

1 Answers1

1

Your "it's not working" image isn't showing any errors, so it seems to start up just fine.

However, the code that handles the request isn't actually sending back a response, which would result in requests just "hanging".

Instead, try this:

https.createServer(options, (req, res) => {
  res.end('Hello, world!');
}).listen(8080, 'localhost', () => {
  console.log('https server start');
});
robertklep
  • 198,204
  • 35
  • 394
  • 381