zatziky zatziky - 1 year ago 101
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

. I can enter

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
which is wrong of course.

How to enter

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download