Create an HTTPS server with Node.js
<p>I'm getting error while trying to access HTTPS server I created with NodeJS.</p>

<p>What do I do : </p>

<p>1.First of all : <a href="https://i.stack.imgur.com/W5U2F.png" rel="nofollow noreferrer">generate a self-signed certificate</a> : </p>

<pre><code>openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
</code></pre>

<p>2.Create simple NodeJs Https server - </p>

<pre><code>var https = require('https');
var fs = require('fs');
var server_port = 8080;

var httpsOptions = {
    key: fs.readFileSync('\key.pem'),
    cert: fs.readFileSync('\cert.pem')
};

var app = function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}   
https.createServer(httpsOptions, app).listen(server_port);
</code></pre>

<ol start="3">
<li><p>run the server : node main.js (the file name)
The server is running but when I try access <a href="https://localhost:8080" rel="nofollow noreferrer">https://localhost:8080</a></p></li>
<li><p>Connect to the server. The result is: </p></li>
</ol>

<p><a href="https://i.stack.imgur.com/W5U2F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W5U2F.png" alt="enter image description here"></a></p>