- For HTTPS Enable we need to install https from npm package :
use the following command [ npm i htps –save ]
- For Free SSL Certificate need to create selfsigned.key and selfsigned.crt files. Go to Create a Self-Signed SSL Certificate
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
// your express configuration here
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(8080);
httpsServer.listen(8443);
Leave a Reply