Reputation: 357
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.!
Upvotes: 0
Views: 1046
Reputation: 203534
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');
});
Upvotes: 1