I am trying to create a secure node.js server to use with my site that is using ssl (https).
const crypto = require(\'crypto\'),
fs = require(\"fs\"),
I have worked on the https secure with the ssl here is the working code for making the https and http
var fs = require('fs');
var http = require('http');
var https = require('https');
var debug = require('debug')('expressapp');
var app = require('../app');
var CONSTANTS = require('../config/CONSTANTS.js');
var AWS = require('aws-sdk');
var certificate =fs.readFileSync('ssl/server.crt',{encoding:'utf8'},function(err, data ) {
console.log( data );});
var privateKey = fs.readFileSync('ssl/server.key',{encoding:'utf8'},function(err, data ) {
console.log( data );});
var credentials = {
key: privateKey,
cert: certificate,
rejectUnauthorized:false
};
// UNCOMMENT THIS LINE AFTER INSTALLING CA CERTIFICATE
//credentials.ca = fs.readFileSync('ssl/server.crt', 'utf8');;
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(CONSTANTS.PORT.HTTP, function() {
console.log('HTTP server listening on port ' + CONSTANTS.PORT.HTTP);
}) ;
httpsServer.listen(CONSTANTS.PORT.HTTPS, function() {
console.log('HTTPS server listening on port ' + CONSTANTS.PORT.HTTPS);
});