How can you serve multiple static directories using Express.js?

  • app.static('directory1'); app.static('directory2');
  • app.use(express.static('directory1')); app.use(express.static('directory2'));
  • app.static('directory1, directory2');
  • app.use(express.static(['directory1', 'directory2']));
To serve multiple static directories in Express.js, you should use the express.static middleware function multiple times with different directory paths. This allows you to specify and configure each static directory separately. The other options are not valid syntax for serving multiple static directories.

In a distributed NoSQL database, the ______ strategy can be used to resolve conflicts between different versions of the same document.

  • Conflict Resolution
  • Versioning
  • Consistency
  • Replication
In a distributed NoSQL database, versioning is a strategy used to resolve conflicts between different versions of the same document. It allows tracking changes and reconciling them when conflicts occur.

In Express.js, which method is used to define a route that should respond to HTTP GET requests?

  • app.post()
  • app.get()
  • app.put()
  • app.delete()
In Express.js, the app.get() method is used to define a route that should respond to HTTP GET requests. It is used to handle GET requests for a specific URL path. The other options (app.post(), app.put(), and app.delete()) are used for different HTTP methods.

You are developing a system where precision is critical, and you have to handle very large integers. Which data type would you use to ensure there is no loss of precision?

  • int
  • float
  • bigint
  • double
When handling very large integers with critical precision, you should use the bigint data type. Unlike int and float, bigint can represent arbitrarily large integers without loss of precision. double is a floating-point type, which may not preserve precision for very large integers.

What is the significance of the main field in the package.json file when publishing a package?

  • It specifies the name of the package.
  • It indicates the primary entry point of the package.
  • It defines the package's version.
  • It lists all the dependencies of the package.
The main field in the package.json file is significant because it specifies the primary entry point of the package. This entry point is the file that will be loaded when someone requires the package. The other options are not the main purpose of the main field.

You are designing a RESTful API and want to ensure that it is secure against injection attacks, what are the various considerations and practices you would implement to sanitize and validate input data?

  • Use parameterized queries and prepared statements.
  • Implement input validation and sanitize user inputs.
  • Avoid using HTTPS for data transmission.
  • Rely on client-side validation for security.
Option (1) is correct. Parameterized queries and prepared statements help prevent SQL injection attacks. Option (2) is also correct, as input validation and sanitation are important for protecting against various injection attacks. Options (3) and (4) are incorrect and insecure practices.

How should developers properly handle unhandled promise rejections in Node.js?

  • Using a global event listener for 'unhandledRejection' events.
  • Ignoring unhandled promise rejections.
  • Manually catching every promise rejection.
  • Using try...catch for all promises.
Properly handling unhandled promise rejections in Node.js involves using a global event listener for 'unhandledRejection' events. This allows developers to log or handle unhandled promise rejections globally, which is crucial for preventing silent errors in applications. Ignoring rejections or manually catching every promise rejection can lead to unexpected and unhandled errors. Using try...catch for all promises is not practical in large applications.

How does the fs Promises API differ from the callback-based API in handling errors?

  • Promises API throws errors synchronously
  • Callback API requires try-catch for errors
  • Promises API uses async/await for error handling
  • Callback API returns errors as the last argument
The fs Promises API differs from the callback-based API by using async/await for error handling. In the Promises API, you can use try-catch to catch errors, making error handling more similar to synchronous code. The callback API, on the other hand, returns errors as the last argument to the callback function.

Which of the following HTTP headers is crucial for preventing Cross-site Scripting (XSS) attacks?

  • Content-Encoding
  • Access-Control-Allow-Origin
  • X-Frame-Options
  • User-Agent
The HTTP header crucial for preventing Cross-site Scripting (XSS) attacks is X-Frame-Options. This header prevents a web page from being embedded within an