title: Node.JS, Express and Heroku - how to handle HTTP and HTTPS?
body: <p>I have an app which is quite normal Express app - simple server logic, views, lots of client-side JS.
  I have to do many AJAX requests. Some of them need to be secured by HTTPS protocol (some needn't).</p>
  
  <p>So, my server should work with both HTTP and HTTPS.
  It should also work o both the local machine (ran with nodemon normally) and on Heroku.</p>
  
  <p>As far as I understood, Heroku gives you a single port (process.env.PORT) you can listen to, and handles all requests through the proxy (so, you app is listening to this port and not bothering about the proto - right?)</p>
  
  <p>So, am I getting this right - I should have some different code for dev machine and Heroku?</p>
  
  <p>Like</p>
  
  <pre><code>...
  app = express()
  ...
  
  if process.env.NODE_ENV == 'production'
    app.listen(process.env.PORT)
  else
    https = require('https')
    http = require('http')
    http.createServer(app).listen(5080) # some local port
    options = {
      key: fs.readFileSync('key.pem'), 
      cert: fs.readFileSync('cert.pem') # my self-signed files
    }
    https.createServer(options, app).listen(5443) # some different local port
  </code></pre>
  
  <p>Is it the proper way to deal with this?</p>