How can middleware functions modify the request and response objects in Express.js?

  • Middleware functions can modify request and response objects directly.
  • Middleware functions cannot modify request and response objects in Express.js.
  • Middleware functions can only modify the request object, not the response object.
  • Middleware functions can only modify the response object, not the request object.
Middleware functions in Express.js have access to the request and response objects, and they can modify these objects directly. This allows them to add, modify, or remove properties and headers, which is useful for various purposes like authentication, logging, and data transformation.

How can you handle errors in middleware in Express.js?

  • Errors in middleware are automatically handled by Express.js and sent as a default error response.
  • Use the next() function with an error object to pass it to an error handling middleware.
  • Errors in middleware should be caught with a try...catch block inside the middleware function.
  • Express.js does not support error handling in middleware.
In Express.js, errors in middleware can be handled by calling next(error) to pass the error to an error handling middleware. This allows for centralized error handling.

Which of the following is true regarding the 'let' keyword in ES6+?

  • let variables are hoisted to the top of their scope.
  • let variables are block-scoped.
  • let variables are globally scoped.
  • let variables cannot be reassigned after declaration.
In ES6+, the let keyword is used to declare variables that are block-scoped, meaning they are limited to the block in which they are declared. Unlike var, let variables are not hoisted to the top of their scope. They can also be reassigned after declaration.

To avoid callback hell while working with the fs module, you can use the ______ API, which returns promises.

  • async
  • await
  • util.promisify
  • Promise
To avoid callback hell when working with the fs module in Node.js, you can use the util.promisify API, which converts callback-based functions into promise-based functions. This allows you to work with promises and async/await syntax, improving code readability and maintainability.

While developing a utility library for DOM manipulation, how can closures be employed to create interface methods while keeping some of the implementation details private?

  • Expose all implementation details in global scope
  • Use closures to create private variables and functions, exposing only necessary interface methods
  • Use global variables to store utility functions
  • Use anonymous functions for all DOM manipulation
Closures can be used to create private variables and functions within the library, allowing you to expose only the necessary interface methods while keeping implementation details private. Exposing all details in the global scope (option a) is not a good practice. Using global variables (option c) and anonymous functions (option d) do not provide the same level of encapsulation and privacy as closures.

JSON Web Tokens (JWT) are composed of three parts: a header, a payload, and a ______.

  • signature
  • key
  • footer
  • token
JSON Web Tokens (JWTs) are composed of three parts: a header, a payload, and a signature. The signature is used to verify the authenticity of the token and ensure that it has not been tampered with. The other options are not components of JWTs.

In schema design, the property that ensures that only valid data is stored in the database is known as ________.

  • Validation
  • Verification
  • Constraints
  • Authentication
In schema design, the property that ensures that only valid data is stored in the database is known as "Constraints." Constraints include rules such as unique keys, primary keys, foreign keys, and check constraints that enforce data integrity and validity.

What is the significance of HTTP/2 in web performance optimization compared to HTTP/1.x?

  • HTTP/2 uses multiplexing to allow multiple requests and responses to be sent in parallel over a single connection.
  • HTTP/2 is a more secure version of HTTP/1.x.
  • HTTP/2 reduces the need for server-side caching.
  • HTTP/2 requires fewer resources on the client-side compared to HTTP/1.x.
HTTP/2 significantly improves web performance compared to HTTP/1.x by introducing features like multiplexing, which allows multiple requests and responses to be sent concurrently over a single connection. This reduces latency and speeds up web page loading. The other options are not accurate representations of HTTP/2's benefits.

When using await inside a function, what does the function return?

  • It returns the resolved value of the awaited Promise.
  • It returns a boolean indicating if the Promise is pending.
  • It returns an array of all pending Promises.
  • It returns an error if the Promise is rejected.
When you use await inside an async function, the function returns the resolved value of the awaited Promise. This enables you to work with asynchronous code in a more synchronous style.

How can you handle errors in a readable stream in Node.js?

  • stream.on('error', (err) => { /* Handle error */ });
  • stream.catch((err) => { /* Handle error */ });
  • stream.error((err) => { /* Handle error */ });
  • try { /* Stream operations */ } catch (err) { /* Handle error */ }
In Node.js, you can handle errors in a readable stream by listening to the 'error' event using stream.on('error', (err) => { /* Handle error */ });. The other options are not the correct way to handle errors in streams.

In JavaScript, variables declared using the var keyword are hoisted to the top of their ________.

  • scope
  • function
  • declaration
In JavaScript, variables declared using the var keyword are hoisted to the top of their containing function's scope. This means that they are moved to the top of the function during the compilation phase, allowing you to use them before they are declared in the code.

You have to deploy a Node.js application, but the production environment does not allow internet access, preventing npm packages from being installed. How do you prepare and install the necessary npm packages in such an environment?

  • Download packages manually and copy them to the production server
  • Use a proxy server to allow internet access for npm
  • Bundle all npm packages with your application during development
  • Ask the production environment to whitelist npm's servers
To install npm packages in an environment without internet access, you can download packages manually and copy them to the production server. This approach ensures the necessary dependencies are available. Using a proxy server or whitelisting npm's servers may not always be feasible.