zatziky zatziky - 3 months ago 8
Node.js Question

How to enter path to tls

In NodeJs I am able to connect to another server over TLS. What I am missing is how to enter

path
. I can enter
host
only.

var tls = require('tls');
var fs = require('fs');

var options = {
key : fs.readFileSync('private.key'),
cert : fs.readFileSync('public.cert')
};

var client = tls.connect(8000, 'localhost', options, function () {
console.log(client.authorized ? 'Authorized' : 'Not authorized');
});


If I do
tls.connect(8000, 'localhost/my_path', ...)
it's resolving to
localhost/my_path:8000
which is wrong of course.

How to enter
path
elements?

Answer

TLS is "merely" a transport layer, on top of which other protocols can be implemented. One is HTTPS.

Since it looks like you want to make HTTPS requests, you'd want to use https.get() instead of using the tls module.

The path parameter of tls.connect() isn't analogous to the path of a URL, it's used to connect to a TLS server through a Unix domain socket (which is represented on the system by a file, which is what the path should point at).