0

Code:

tls.createServer(options, function (s) {
  s.write(msg+"\n");
  s.pipe(s);
}).listen(8000);

Problem:

1 I can NOT find something like class/type of param s. As typeeof only return Object.

2 However, for method belong to this s, like s.pipe/s.write.

Is there some way to find some info/definition related?

Ref: https://docs.nodejitsu.com/articles/cryptography/how-to-use-the-tls-module/

Thank you very much.

Note: 1 I mostly from a C-language backgronup.
2 I hope there is some way to find class of variable s, then I can go to that class manual to find info/definition of methods like pipe/join.
3 Not sure whether it is the right way to do things in nodejs.

1 Answers1

0

It stands for socket.

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

const options = {
  key: fs.readFileSync('server-key.pem'),
  cert: fs.readFileSync('server-cert.pem'),

  // This is necessary only if using the client certificate authentication.
  requestCert: true,

  // This is necessary only if the client uses the self-signed certificate.
  ca: [ fs.readFileSync('client-cert.pem') ]
};

const server = tls.createServer(options, (socket) => {
  console.log('server connected',
              socket.authorized ? 'authorized' : 'unauthorized');
  socket.write('welcome!\n');
  socket.setEncoding('utf8');
  socket.pipe(socket);
});
server.listen(8000, () => {
  console.log('server bound');
});

https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener