QA
Intermediate LevelNode JS

How do you configure HTTPS and TLS/SSL servers using node:https and node:tls?

❓ Interview Prompt: Explain `node:https`, `node:tls`, TLS/SSL handshakes, private key (`key`), public certificate (`cert`), and SNI (Server Name Indication).

Securing Node.js HTTP servers requires TLS/SSL certificate configuration via 'node:https':

•
'key': Private RSA/ECC key.
•
'cert': Public SSL/TLS certificate issued by a Certificate Authority (CA).
•
SNI ('SNICallback'): Dynamically serves different SSL certificates based on the target domain requested in the TLS handshake.

Code Implementation Example

javascript
import https from 'node:https';
import fs from 'node:fs';

const options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt')
};

https.createServer(options, (req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Secure HTTPS connection established!');
}).listen(443);
💡Configuring a secure HTTPS server using private key and certificate.
🎯 Interview Key Takeaway

Provide valid key and cert options to node:https to create TLS/SSL encrypted servers.

#https#tls#SSL#Security#Intermediate
Back to all Node JS Questions→

More Node JS Interview Questions

Beginner LevelNode JS

How does the Node.js Event Loop work? Explain the 6 execution phases (Timers, Pending, Poll, Check, Close).

Beginner LevelNode JS

What does 'Single-Threaded, Event-Driven, Non-Blocking I/O' mean in Node.js?

Beginner LevelNode JS

What is the difference between process.nextTick() and setImmediate()?