Module "https" and "http"" Flashcards

(46 cards)

1
Q

Module “http”: What is http.createServer?

A

Creates a new HTTP server instance that handles requests via a callback.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Module “http”: What are req and res in http.createServer?

A

Instances of http.IncomingMessage and http.ServerResponse.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Module “http”: How do you start a server?

A

server.listen(port, hostname, callback)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Module “http”: How do you read request body?

A

Listen to ‘data’ and ‘end’ events on req stream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Module “http”: Why is request body a stream?

A

To process data incrementally without loading entire payload into memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Module “http”: How do you send response?

A

Use res.write() and res.end().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Module “http”: What does res.end() do?

A

Finalizes and sends the response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Module “http”: Difference between res.write and res.end?

A

write sends chunks, end finishes response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Module “http”: What is res.writeHead?

A

Sets status code and headers in one call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Module “http”: Difference between res.setHeader and res.writeHead?

A

setHeader queues headers, writeHead sends them immediately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Module “http”: How to set status code?

A

res.statusCode = 200

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Module “http”: What happens if res.write is called after res.end?

A

Throws an error because response is already finished.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Module “http”: How to stream a file to client?

A

fs.createReadStream(path).pipe(res)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Module “http”: What is http.request?

A

Used to make HTTP requests as a client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Module “http”: Difference between http.request and http.get?

A

http.get is a simplified version for GET requests.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Module “http”: How do you send POST request?

A

Use http.request with method ‘POST’ and write body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Module “http”: What is http.Agent?

A

Manages connection pooling and reuse of sockets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Module “http”: How to enable keep-alive?

A

Use http.Agent with keepAlive: true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Module “http”: What is req.socket?

A

Underlying TCP socket.

20
Q

Module “http”: How to access headers?

21
Q

Module “http”: What event handles incoming data?

A

‘data’ event

22
Q

Module “http”: What event signals request end?

A

‘end’ event

23
Q

Module “http”: How to handle aborted request?

A

Listen to ‘aborted’ or ‘close’ events on req.

24
Q

Module “http”: What is server.close()?

A

Stops the server from accepting new connections.

25
Module "http": How to handle server errors?
Listen to 'error' event on server.
26
Module "http": What is chunked transfer encoding?
Sending response in chunks without Content-Length.
27
Module "http": How to manually parse URL?
Use new URL(req.url, base).
28
Module "http": What is http.IncomingMessage?
Represents incoming request.
29
Module "http": What is http.ServerResponse?
Represents outgoing response.
30
Module "http": How to handle timeouts?
server.setTimeout() or req.setTimeout().
31
Module "https": What is https module?
HTTP over TLS providing encrypted communication.
32
Module "https": How to create HTTPS server?
https.createServer({ key, cert }, handler)
33
Module "https": What is required for HTTPS server?
SSL/TLS certificate and private key.
34
Module "https": What is TLS?
Protocol providing encryption and secure communication.
35
Module "https": What is https.request?
Client method for making HTTPS requests.
36
Module "https": What is https.get?
Simplified GET request over HTTPS.
37
Module "https": What is https.Agent?
Manages HTTPS connections and TLS settings.
38
Module "https": How to enable keep-alive in HTTPS?
Use https.Agent with keepAlive: true.
39
Module "https": What is rejectUnauthorized option?
Controls whether invalid SSL certs are rejected.
40
Module "https": What happens if certificate is invalid?
Request fails unless rejectUnauthorized is false.
41
Module "https": How to pass custom CA?
Provide ca option in request or agent.
42
Module "https": What is SNI?
Server Name Indication for selecting certificate by hostname.
43
Module "https": What is handshake?
Process of establishing secure TLS connection.
44
Module "https": What is ALPN?
Protocol negotiation (e.g., HTTP/1.1 vs HTTP/2).
45
Module "https": How to debug HTTPS issues?
Check certificates, enable logging, inspect TLS errors.
46
Module "https": What is key difference from http module?
Adds TLS encryption layer over HTTP.