Challenge your understanding of the Deno standard library, covering core modules for file handling, HTTP servers, utilities, and more. This quiz helps reinforce practical knowledge needed for efficient development with Deno’s built-in tools and APIs.
Which function from the Deno standard library allows you to read the entire contents of a text file as a string?
Explanation: The readTextFile function reads the contents of a text file and returns it as a string. Options like getFileString and readFileToText are not actual functions in the standard library, making them incorrect. loadTextFile also does not exist as a function and may confuse with similar names. Only readTextFile correctly reads a text file as a string.
What standard library module provides the serve function for creating a basic HTTP server?
Explanation: The http module contains the serve function, which is essential for setting up HTTP servers. The net module deals with lower-level network functionality rather than HTTP specifically. servers and network are not valid module names in the standard library. Therefore, only http is the right choice for HTTP server creation.
How do you retrieve an environment variable named 'PORT' using the standard library utilities?
Explanation: The correct method to get an environment variable is Deno.env.get('PORT'). getEnv('PORT') and Environment.get('PORT') are incorrect as such functions do not exist. env.PORT looks like object property access but is not part of the standard API. Thus, Deno.env.get('PORT') is the proper approach.
Which module provides utilities like join, basename, and extname for working with file paths?
Explanation: The path module offers various helpers such as join, basename, and extname for manipulating and analyzing file paths. fs is intended for file system operations, not path manipulations. fileutils and dir are not modules in the standard library. path is the only module designed for these kinds of utilities.
If you need to generate a version 4 UUID, which standard library module should you import?
Explanation: uuid is the module dedicated to generating universally unique identifiers, including version 4 UUIDs. The id, unique, and hash modules either do not exist or serve different purposes unrelated to UUIDs. Only uuid offers UUID generation functions.
What function from the testing module would you use to check if two values are strictly equal in a test?
Explanation: assertEquals is the correct function for verifying strict equality between two values during testing. assertIsEqual and equalAssert sound plausible but are not actual assertion functions in the standard library. assertSame is also not a provided method. Only assertEquals should be used here.
Which function lets you write a string to a text file, overwriting any existing content?
Explanation: writeTextFile will write a string to a file, replacing the existing contents if the file exists. appendTextFile sounds similar but would suggest adding to the existing content, which is not correct here. writeFileText and saveTextFile are not valid standard library functions. Therefore, writeTextFile is the right option.
Which module provides functions for formatting and parsing dates?
Explanation: The datetime module supplies utilities for both formatting and parsing dates. dates, dateutils, and time are plausible-sounding names, but they are not actual module names in the standard library. Thus, datetime is the correct answer.
Which function checks if a file or directory exists without throwing an error if it does not?
Explanation: The exists function will return a boolean indicating whether the file or directory is present, avoiding exceptions on absence. fileExists is not the actual function name, making it incorrect. stat retrieves file stats but throws an error if the file does not exist. checkFile is not a standard function. Only exists is correct.
Which module helps parse command-line arguments in an easy and structured way?
Explanation: The flags module is designed to parse command-line flags and arguments efficiently. args and cli sound relevant but are not actual standard library modules for this purpose. options could be misleading but is also not correct. Therefore, flags is the right module to use for command-line parsing.