node.js https server not loading responding
<p>I am trying to start a https node.js server. </p>

<p>I started by creating a certificate and key following this guide:</p>

<p><a href="http://gaboesquivel.com/blog/2014/nodejs-https-and-ssl-certificate-for-development/">http://gaboesquivel.com/blog/2014/nodejs-https-and-ssl-certificate-for-development/</a></p>

<p>and I placed them in my <code>/app_name/security/keys</code> directory.</p>

<p>To start my https server, I have the following:</p>

<pre><code>const https         = require('https'),
      fs            = require('fs');

if(app.get('env') === 'development') {

    console.log('dev env!!'); //prints correctly
    console.log('port: ' + port); //prints correctly
    const options = {
        key: fs.readFileSync('./security/keys/key.pem'),
        cert: fs.readFileSync('./security/keys/cert.pem')
    };   

    https.createServer(options, (req, res) =&gt; {

        console.log('https good to go'); //this does not print out anything

    }).listen(port);

}
</code></pre>

<p>When I go to <code>https://localhost:3000</code>, the page throws an error</p>

<pre><code>This site can’t be reached

localhost unexpectedly closed the connection.
ERR_CONNECTION_CLOSED
</code></pre>

<p>But there's no error on the server side console. Furthermore, if i go to the regular <code>localhost:3000</code>, I get:</p>

<pre><code>The localhost page isn’t working

localhost didn’t send any data.
ERR_EMPTY_RESPONSE
</code></pre>

<p>Can someone help?</p>

<p>Thanks in advance!</p>

<p>---- UPDATE ----</p>

<p>I'm running on port 443 now. Initially I got an error: </p>

<p><code>Error: listen EACCES 0.0.0.0:443</code> so I ran:</p>

<p><code>sudo NODE_ENV=development nodemon app</code></p>

<p>Which did not throw any errors. However, when I went to <code>https://localhost:443</code>, I get:</p>

<pre><code>This site can’t be reached

localhost unexpectedly closed the connection.
</code></pre>