Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

186
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda