Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Converting NodeJs / express HTTP server to HTTPS

So I have a basic NodeJS server which I am trying to convert from HTTP to HTTPS.

Here is the old code (HTTP) which works:

const express = require('express');
const port = 80;

const app = express();

app.listen(port, () => console.log('listening on ' + port));
app.use(express.static('public'));
app.use(express.json({'limit':'2mb'}));

I've been looking up how to convert this to HTTPS. I have tried many attempts but I just cant seem to get this working. Below is my current state of code.

New code (HTTPS) does not work:

const express = require('express');
const https = require('https');
const fs = require('fs');
const port = 443;

var key = fs.readFileSync('./private/privkey.pem');
var cert = fs.readFileSync('./private/fullchain.pem');

var options = {
    key: key,
    cert: cert
  };

var app = express();

https.createServer(options, app).listen(port, () => console.log('listening on ' + port));
app.use(express.static('public'));
app.use(express.json({'limit' : '2mb'}));

The port does seem to open and listen but whenever I try to connect via browser, I get the error:

"<ip> didn’t send any data." ERR_EMPTY_RESPONSE

I have tried omitting the express app from the https server and replacing with

function (req, res) { res.send('hello!') }

But this did not make any difference in the error.

I am truly stuck now as I have checked so many forums and I don't know what I'm doing wrong.

EDIT:

I am not getting any syntax errors from running index.js

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!