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

259
Vistas
Trying to run express node js as https server but it won't run

I'm trying to get HTTPS working on express.js for node, and it won't run.

This is my server.js code.

const fs = require('fs');
const http = require ('http');
const https = require('https');

const options = {
    pfx: fs.readFileSync('ssl/pfxfile.pfx'),
    passphrase: 'password'
};
const express = require('express');
const app = express();

const path = require('path');
    app.use(express.json());
    app.use(express.static("express"));
    app.use('/', function(req,res){
        res.sendFile(path.join(__dirname+'/express/index.html'));
    });
 
var httpServer = http.createServer(app);
var httpsServer = https.createServer(options, app);

httpServer.listen(8080);
httpsServer.listen(8443);

When I run it reports no errors but it just get stuck to nothing (I waited 30 minutes to see if it does something and nothing happened).

Console Screenshot

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

httpServer.listen(8080, ()=>{console.log('Server is running')}); If the server successfully started, it should output "Server is running" in the console. This is a nice way to check if the server is working as intended.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I found my error, thanks for your answers, it's been helping me, my error was first that I didn't put any console.log and the second was that I was not typing 8443 in the browser.

const fs = require('fs');
const http = require('http');
const https = require('https');

const options = {
    pfx: fs.readFileSync('ssl/pfxfile.pfx'),
    passphrase: 'password'
};
const express = require('express');
const app = express();

const path = require('path');
    app.use(express.json());
    app.use(express.static("express"));
    app.use('/', function(req,res){
        res.sendFile(path.join(__dirname+'/express/index.html'));
    });
 
const httpServer = http.createServer(app);
const port = process.env.PORT || 8080;
const httpsServer = https.createServer(options, app);
const portHttps = process.env.PORT || 8443;

httpServer.listen(port, () => console.log('Http listening on port ' + port));
httpsServer.listen(portHttps, () => console.log('Https listening on port ' + portHttps));
about 4 years ago · Juan Pablo Isaza Denunciar
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