The Buffer class in Node.js is a global class and can be accessed in an application without importing the ______ module.

  • fs
  • net
  • buffer
  • http
The Buffer class in Node.js is available globally, so it can be accessed without importing any specific module. This is one of the unique features of the Buffer class in Node.js.

What command will uninstall a Node.js package?

  • npm remove
  • npm delete
  • npm uninstall
  • npm purge
To uninstall a Node.js package, you should use the npm uninstall command. This command removes the package from the current project. The other options are either incorrect or not the standard way to uninstall a package.

When defining dynamic routes in Express.js, using :param* will match ______ in the route path.

  • param
  • :param
  • *param
  • :param*
In Express.js, when defining dynamic routes, using :param* will match any characters after param in the route path and store them as a parameter in the request object. The other options do not represent the correct syntax for defining dynamic routes in Express.js.

You are building a chat application in Node.js and need to handle different types of messages like text, images, and files. How would you structure the event emitters and listeners to handle different message types efficiently?

  • Create separate events for each message type: event.emit('textMessage', message)
  • Use a single event and send message type as a parameter: event.emit('message', messageType, message)
  • Create a listener for each message type: event.on('textMessage', textMessageCallback)
  • Create a single listener and use conditional checks to handle message types: event.on('message', messageCallback)
To efficiently handle different message types in a chat application, it's best to create separate events for each message type (e.g., 'textMessage', 'imageMessage', 'fileMessage'). This approach keeps the code organized and allows specific handlers for each message type. The other options may lead to less structured and harder-to-maintain code.

What is the main purpose of the global object in Node.js?

  • To manage global variables
  • To handle exceptions globally
  • To control the execution flow of the program
  • To define local variables
The main purpose of the global object in Node.js is to manage global variables and provide a context for globally accessible methods and properties. It is not primarily responsible for handling exceptions, controlling execution flow, or defining local variables.

In Express, which method is used to start a server listening for connections?

  • app.listen()
  • server.start()
  • express.startServer()
  • node.start()
In Express, you use the app.listen() method to start a server that listens for incoming connections. This method binds the server to a specified port and hostname, allowing it to handle HTTP requests. The other options are not valid methods for starting an Express server.

In JavaScript, the ______ property is used to set up inheritance between custom types.

  • inherit
  • prototype
  • extend
  • object
In JavaScript, the prototype property is used to set up inheritance between custom types. It allows one object to inherit properties and methods from another object. This is a fundamental concept in JavaScript's object-oriented programming model.

How can you ensure that a specific script in package.json runs only after another specified script has successfully completed?

  • Using npm's pre and post scripts
  • Using conditional statements in JavaScript
  • It's not possible to achieve this in package.json
  • By using a third-party package
In package.json, you can use pre and post scripts to define the order in which scripts should run. For example, if you want a script to run after another, you can use "pre": "npm run firstScript" and "post": "npm run secondScript". This ensures that secondScript runs after firstScript.

In Express.js, what does the next() function do in middleware?

  • Ends the request-response cycle
  • Sends an HTTP response
  • Passes control to the next middleware function
  • Logs a message to the console
In Express.js, the next() function is used in middleware to pass control to the next middleware function in the stack. It allows the request to continue processing through subsequent middleware functions. If you don't call next(), the request-response cycle may be terminated, and subsequent middleware or route handlers won't be executed.

Which of the following is a common technique used for implementing full-text search in databases?

  • Regular Expressions
  • Binary Search
  • Inverted Index
  • Depth-First Search
A common technique for implementing full-text search in databases is the use of an inverted index. This index stores a list of words or terms along with the locations where they appear in the documents, making it efficient for searching large volumes of text. Regular expressions, binary search, and depth-first search are not typically used for full-text search in databases.