What would be the best way to handle errors in an Express application when building RESTful APIs?

  • Using try...catch blocks in route handlers
  • Sending 404 Not Found for all errors
  • Using console.log() for error messages
  • Not handling errors, let them crash the server
The best way to handle errors in an Express application when building RESTful APIs is to use try...catch blocks in route handlers. This allows you to catch errors and send appropriate HTTP responses with error details. Sending 404 Not Found for all errors is not a good practice, and letting errors crash the server is even worse. Console.log() is generally used for debugging but not for handling errors.

You are maintaining a library, and you need to release a new version that fixes a bug but also changes the behavior of an existing feature. How should you update the version number according to semantic versioning?

  • 1.0.0
  • 1.1.0
  • 2.0.0
  • 1.0.1
According to semantic versioning (SemVer), when you make backward-incompatible changes or breaking changes, you should increment the major version. In this scenario, since the behavior change affects existing users, you should update to version 2.0.0.

Which command is used to install a Node.js package globally?

  • npm global install
  • npm i -g
  • npm install -g
  • npm add -g
To install a Node.js package globally, you should use the npm install -g command. This makes the package available for use across different projects. The other options may not work as expected or are not the recommended way to install packages globally.

When implementing indexing, what factors should be considered to mitigate the impact on database write performance?

  • Selective indexing
  • Index maintenance strategy
  • Using index-only scans
  • Increasing index size
When implementing indexing, factors to consider for mitigating the impact on write performance include selective indexing (indexing only the columns that are frequently queried), choosing an appropriate index maintenance strategy (e.g., periodic maintenance rather than immediate updates), and using index-only scans to reduce disk I/O during reads. Increasing the index size can have a negative impact on write performance, so it should be done judiciously.

In Node.js, how can data be written to a writable stream?

  • Using the read() method
  • Using the write() method
  • Using the pipe() method
  • Using the readable() method
Data can be written to a writable stream in Node.js using the write() method. This method allows you to write data to the stream, which can be a file, network connection, or any other writable destination. The pipe() method is used for piping data from a readable stream to a writable stream, and the other options are not the correct ways to write data to a writable stream.

To perform an action once a Promise is settled, regardless of its outcome, you can use the .finally() method, which is called on the ________ of a Promise.

  • rejection
  • resolution
  • completion
  • termination
To perform an action once a Promise is settled, regardless of whether it's fulfilled or rejected, you can use the .finally() method. This method is called on the "completion" of a Promise. It's often used for cleanup operations.

You are tasked with implementing an authentication system for your Express API. What considerations should you make regarding security, user experience, and scalability when choosing an authentication strategy?

  • Use JWT (JSON Web Tokens) with long expiration times.
  • Store plain text passwords in the database.
  • Implement OAuth 2.0 for social login only.
  • Use basic authentication over HTTP.
Using JWT with long expiration times might seem like a convenient option for user experience, but it could pose a security risk. Storing plain text passwords is a severe security vulnerability. Implementing OAuth 2.0 for social login only might not be sufficient for all authentication needs. Using basic authentication over HTTP is not secure. A robust authentication strategy should consider security (option 1) without compromising user experience and

You are building a dynamic form generator. You need to ensure that the data types of the input values are preserved when sent to the server. What approach should you take for data type preservation when stringifying the inputs?

  • JSON.stringify(inputs);
  • inputs.toString();
  • String(inputs);
  • inputs.join(",");
To preserve data types when stringifying inputs, you should use JSON.stringify(inputs);. This method serializes data to a JSON string, which can later be parsed back into their original data types. The other options do not provide the same level of data type preservation.

What will happen if there are conflicting names when importing items from a module?

  • The last imported item with the conflicting name will override the previous ones.
  • An error will occur, and you will need to manually resolve the conflict by renaming the items.
  • JavaScript will automatically assign unique names to the conflicting items.
  • Conflicting names are not allowed when importing items from a module.
In JavaScript, when you import items from a module, if there are conflicting names (e.g., two imported items have the same name), the last imported item with the conflicting name will override the previous ones. This can lead to unexpected behavior and should be avoided by using unique and descriptive names for imported items.

To run a pre-hook for a custom script named "build," you would define a script named ______ in your package.json file.

  • prebuild
  • pre-hook
  • beforebuild
  • pre-build
To run a pre-hook for a custom script named "build" in your package.json file, you would define a script named prebuild. This allows you to execute tasks before the "build" script is run, such as setting up dependencies or configurations. The other options do not follow the standard naming convention for npm pre-hooks.