title: Where am I supposed to store my key and cert for an https server (Node.js)
body: <p>I'm very new to ssl and am having trouble setting up my node project with https. I've signed up and got a free certificate from StartSSL. I've got my private key in a file called key.pem. I've validated my domain name and have my certificate in a cert.pem file. </p>
  
  <p>Here's how I had my server set up on HTTP: </p>
  
  <pre><code>    var server = require('http').createServer(app);
      var port = process.env.PORT || 3000;
      server.listen(port, function () {
        console.log('Server listening at port %d', port);
      });
  </code></pre>
  
  <p>This works fine, all my pages loaded accordingly.
  Here's what how I'm trying to set up my https server: </p>
  
  <pre><code>var https = require("https");
  var fs = require("fs");
  var key_file   = "key.pem";
  var cert_file  = "cert.pem";
  var passphrase = "...";
  var config     = {
    key: fs.readFileSync(key_file),
    cert: fs.readFileSync(cert_file),
    passphrase: passphrase
  };
  var server = https.createServer(config,app).listen(443);
  </code></pre>
  
  <p>The problem is that localhost won't load anything. I don't get any errors in my console, which is annoying because I have no clue what I'm doing wrong. As you can see I'm just putting my key and cert in the root of my project, which I'm not sure if I'm supposed to do or it. 
  Shouldn't I just be able to got to localhost:443 or <a href="https://localhost:443" rel="nofollow">https://localhost:443</a> and see my website? I've tried to follow like 6 tutorials now and can't seem to get anything to work. Am I even doing this right? Because I'm not getting any certificate from the client which I thought I was supposed to do.</p>
  
  <p>Tried this as well which also didn't work:</p>
  
  <pre><code>var https = require("https");
  var constants = require("constants");
  var fs = require("fs");
   var passphrase = "...";
  https.createServer({
      key: fs.readFileSync("key.pem"),
      cert: fs.readFileSync("cert.pem"),
      passphrase: passphrase,
      secureProtocol: 'SSLv23_method',
      honorCipherOrder: true,
      secureOptions: constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_SSLv2
  }, function(req, res) {
      req.end("Hello, SSL World!");
  }).listen(443, function() {
      console.log("SSL Proxy listening on port 443");
  });
  </code></pre>
  
  <p>Can't get the hello world even though it says it's listening on 443 in the console.  </p>
  
  <hr>
  
  <p>EDIT: 
  This is my entire index.js and I still can't get the hello world. All the dependencies are installed. What could be the issue?</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var https = require("https");
  var fs = require("fs");
  var options = {
    key: fs.readFileSync('key.pem'),
    cert: fs.readFileSync('cert.pem')
  };
  https.createServer(options, function (req, res) {
    res.writeHead(200);
    res.end("hello world\n");
  }).listen(8000);
  </code></pre>