hcohen hcohen - 5 months ago 46
Javascript Question

Create an HTTPS server with Node.js

I'm getting error while trying to access HTTPS server I created with NodeJS.

What do I do :

1.First of all : generate a self-signed certificate :

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem

2.Create simple NodeJs Https server -

var https = require('https');
var fs = require('fs');
var server_port = 8080;

var httpsOptions = {
key: fs.readFileSync('\key.pem'),
cert: fs.readFileSync('\cert.pem')

var app = function (req, res) {
res.end("hello world\n");
https.createServer(httpsOptions, app).listen(server_port);

  1. run the server : node main.js (the file name)
    The server is running but when I try access https://localhost:8080

  2. Connect to the server. The result is:

enter image description here


try with:

openssl genrsa -out key.pem 1024


openssl genrsa -out key.pem 2048

A key size of 512 is considered weak