G
G
German Zvonchuk2015-10-16 23:57:42
Node.js
German Zvonchuk, 2015-10-16 23:57:42

How to enable SSL in NodeJS v4.2.1 without using Express.js?

Goodnight.
Installed NodeJS v4.2.1 on Debian Jessie, connected the Socket.IO framework to deliver data via web socket to the browser.
I ran into a problem, I could not connect certificates to connect to NodeJS via HTTPS.
All the examples and documentation say that in order to connect a certificate to NodeJS, you need to use another Express.js framework, is this really true? Or have I misunderstood something?
Here is my working configuration:

var fs = require('fs');
var express = require('express');
var app = express();

var options = {
  key: fs.readFileSync('/home/quotes/ssl/domain.key'),
  cert: fs.readFileSync('/home/quotes/ssl/domain.crt'),
  ca: fs.readFileSync('/home/quotes/ssl/gd_bundle-g2-g1.crt'),
  requestCert: true,
  rejectUnauthorized: false,
}

var server = require('https').createServer(options, app);
var io = require('socket.io').listen(server);

You can somehow connect an SSL certificate without using the Express.js framework.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Timur Shemsedinov, 2015-10-17
@MarcusAurelius Node.js tag curator

Have you looked into the docks of the nodes?
First instance: https://nodejs.org/api/https.html#https_https_crea...

K
Konstantin Kitmanov, 2015-10-17
@k12th

What's with the dislike of official documentation?https://nodejs.org/api/https.html#https_https_crea... , everything works fine without express.

G
German Zvonchuk, 2015-10-19
@inside22

Timur Shemsedinov and Konstantin Kitmanov , thank you very much. I'm starting to smoke documentation.
Am I thinking right?
First, I create httpsOptions settings, then I load https, then I create a server with https and with the necessary settings, and then I load socket.io and say that we need to use the already created server.
Am I thinking right?

var fs = require('fs');

var httpsOptions = {
        key: fs.readFileSync('/home/quotes/ssl/domain.key'),
        cert: fs.readFileSync('/home/quotes/ssl/domain.crt'),		
        ca: fs.readFileSync('/home/quotes/ssl/gd_bundle-g2-g1.crt'),
        requestCert: true,
        rejectUnauthorized: false,
}

var https = require('https');
var server = https.createServer(httpsOptions, https).listen(8443);

var io = require('socket.io');	
var app = io.listen(server);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question