title: NodeJS listening on HTTP and HTTPS for one single domain name
body: <p>I use express and a server cloud on AWS (Amazon Web Server) and a DNS "mydomain.com".</p>
  
  <p>Question: how can I avoid my users to have to writing in the Browser-URL: <a href="http://mydomain.com:4000" rel="nofollow">http://mydomain.com:4000</a> and <a href="https://mydomain.com:3000" rel="nofollow">https://mydomain.com:3000</a></p>
  
  <p>This is my code:</p>
  
  <p>sudo node app.js</p>
  
  <pre><code>var app = express();
  var server = http.createServer(app).listen(4000, function() {
          console.log('Express HTTP server listening on port ' + app.get('port'));
  });
  var server = https.createServer(credentials, app).listen(3000, function() {
          console.log('Express HTTPS server listening on port 3000');
  });
  
  // redirect all http requests to https
  app.use(function(req, res, next) {
    if(!req.secure) {
      return res.redirect(['https://mydomain.com', req.url].join(''));
    }
    next();
  });
  </code></pre>
  
  <p>I want my user to be able to write my domain name using http and https with no port numbers. I already have a SSL certificate and everything is working fine, but I haven't been able remove the port-numbers and use both: https and http.</p>
  
  <p>Any idea? please :)</p>
  
  <p>I use MEAN stack (Mongo, Express, Angular, )</p>