Skip to content
QuiznExam

HTTP & HTTPS Modules in Node.js

Test your knowledge of the HTTP and HTTPS modules in Node.js, including creating servers, handling requests and responses, HTTP methods, status codes, headers, HTTPS, and TLS certificates.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which built-in Node.js module is used to create HTTP servers and handle HTTP requests?

    • A. http
    • B. server
    • C. web
    • D. request
    Show answer

    A. http

    The built-in http module provides APIs for creating HTTP servers and handling HTTP requests and responses.

  2. 2. How can the built-in HTTP module be imported using CommonJS?

    • A. const http = require('http');
    • B. import http from 'node-http';
    • C. include http;
    • D. require.module('http');
    Show answer

    A. const http = require('http');

    The CommonJS syntax require('http') loads Node.js's built-in HTTP module.

  3. 3. Which method creates an HTTP server in Node.js?

    • A. http.createServer()
    • B. http.newServer()
    • C. http.startServer()
    • D. http.server()
    Show answer

    A. http.createServer()

    The http.createServer() method creates and returns an HTTP server.

  4. 4. Which method is used to make an HTTP request using Node.js's HTTP module?

    • A. http.fetch()
    • B. http.request()
    • C. http.send()
    • D. http.call()
    Show answer

    B. http.request()

    The http.request() method initiates an HTTP request and provides control over request options and the response.

  5. 5. Which method is commonly used for a simpler HTTP GET request in Node.js?

    • A. http.get()
    • B. http.fetchGet()
    • C. http.read()
    • D. http.retrieve()
    Show answer

    A. http.get()

    http.get() is a convenience method for making HTTP GET requests and automatically calls request.end().

  6. 6. Which property of the incoming request object contains the HTTP method?

    • A. req.type
    • B. req.method
    • C. req.httpMethod
    • D. req.action
    Show answer

    B. req.method

    The req.method property contains the HTTP method, such as GET, POST, PUT, or DELETE.

  7. 7. Which property of the incoming HTTP request contains the requested URL?

    • A. req.path
    • B. req.address
    • C. req.url
    • D. req.location
    Show answer

    C. req.url

    The req.url property contains the request URL string, including the path and query string.

  8. 8. Which method is commonly used to send an HTTP status code and headers in a Node.js response?

    • A. res.status()
    • B. res.writeHead()
    • C. res.sendHead()
    • D. res.header()
    Show answer

    B. res.writeHead()

    The res.writeHead() method writes the status code and response headers to the response.

  9. 9. Which method sends response body data to the client without necessarily ending the response?

    • A. res.write()
    • B. res.send()
    • C. res.body()
    • D. res.push()
    Show answer

    A. res.write()

    res.write() writes a chunk of response body data. The response can later be completed with res.end().

  10. 10. Which method is used to finish an HTTP response?

    • A. res.finish()
    • B. res.close()
    • C. res.end()
    • D. res.stop()
    Show answer

    C. res.end()

    res.end() signals that the response is complete and can optionally send a final piece of data.

  11. 11. Which built-in Node.js module is used to create HTTPS servers and make HTTPS requests?

    • A. secure
    • B. tls-http
    • C. https
    • D. ssl
    Show answer

    C. https

    The built-in https module provides HTTPS functionality built on top of TLS/SSL and the HTTP module.

  12. 12. Which method creates an HTTPS server in Node.js?

    • A. https.createServer()
    • B. https.newServer()
    • C. https.start()
    • D. https.secureServer()
    Show answer

    A. https.createServer()

    The https.createServer() method creates an HTTPS server and accepts TLS options such as a certificate and private key.

  13. 13. What is the main security advantage of HTTPS over HTTP?

    • A. It makes JavaScript execute faster
    • B. It encrypts data exchanged between the client and server
    • C. It removes the need for a server
    • D. It automatically compresses every response
    Show answer

    B. It encrypts data exchanged between the client and server

    HTTPS uses TLS to provide encrypted communication and helps protect data from interception and tampering.

  14. 14. Which type of information is typically required when creating an HTTPS server?

    • A. Private key and certificate
    • B. HTML and CSS files
    • C. Database username and password
    • D. JavaScript source map
    Show answer

    A. Private key and certificate

    An HTTPS server typically requires TLS credentials such as a private key and a certificate.

  15. 15. What is the relationship between Node.js's HTTPS and HTTP modules?

    • A. HTTPS is unrelated to HTTP
    • B. HTTPS provides HTTP functionality over TLS
    • C. HTTP is built on top of HTTPS only
    • D. HTTPS is used only for file transfers
    Show answer

    B. HTTPS provides HTTP functionality over TLS

    Node.js's HTTPS module extends HTTP functionality by providing HTTP communication secured with TLS.