What does the scripts section in the package.json file primarily contain?
- Dependencies
- Code comments
- Build instructions
- Custom command shortcuts
The scripts section in the package.json file primarily contains custom command shortcuts. These shortcuts allow you to run commonly used commands for your project, such as starting the application, running tests, or building the project. They are defined as key-value pairs where the key is the name of the command, and the value is the command to execute.
In OAuth 2.0, the ________ endpoint is used by the client to obtain the authorization from the resource owner.
- Authorization
- Token
- Redirect
- Consent
In OAuth 2.0, the "Authorization" endpoint is used by the client to obtain authorization from the resource owner. This step is part of the OAuth 2.0 authorization code flow, where the client redirects the resource owner to the authorization server to grant access. The "Token" endpoint (Option 2) is used to exchange an authorization code for an access token. The "Redirect" endpoint (Option 3) typically refers to where the authorization server redirects the resource owner after granting or denying access. "Consent" (Option 4) is a user interaction step but not an OAuth endpoint.
What is the proper way to handle errors in EJS views?
- try-catch
- error-handler middleware
- if-else
- throw
In EJS views, the proper way to handle errors is by using error-handler middleware in your Node.js application. This middleware can catch and handle errors, allowing you to display appropriate error pages or messages in your views. The other options (try-catch, if-else, and throw) are not typically used for handling errors in EJS views.
CORS is a security feature implemented by ________.
- Web browsers
- Server-side frameworks
- Client-side libraries
- Database systems
CORS (Cross-Origin Resource Sharing) is a security feature implemented by web browsers. It allows or restricts web applications running at one origin (domain) to make requests for resources located on a different origin.
How can you implement a custom writable stream in Node.js?
- util.promisify
- stream.pipeline
- Writable class
- Readable class
To implement a custom writable stream in Node.js, you should extend the Writable class and implement its _write method. This method is responsible for processing and writing data to the stream. The other options are not used for creating custom writable streams.
You are developing a JavaScript library that will be used by other developers. How can ESLint help in ensuring that the code is error-free and adheres to best practices before being published?
- ESLint cannot help in library development.
- Use ESLint to identify and fix coding errors, enforce coding standards, and ensure best practices are followed.
- Rely on user feedback after publishing the library to identify and fix issues.
- Hire a dedicated code reviewer to manually inspect the code.
ESLint can be a valuable tool in library development. It helps identify and fix coding errors, enforces coding standards, and ensures best practices are followed, reducing the likelihood of issues arising after publication. Relying solely on user feedback or manual code inspection may lead to post-release issues.
In the http module, the ______ method of the response object is used to write a chunk of the response body.
- send
- write
- respond
In the http module, the write method of the response object is used to write a chunk of the response body. This method is typically used in scenarios where you want to stream data to the client as it becomes available, such as when serving large files.
Closures can be used to create ________ functions, which can maintain their own state independently.
- anonymous
- arrow
- stateful
- pure
Closures can be used to create stateful functions. These functions can maintain their own state independently because they have access to the variables in their containing closure. This allows them to remember data across multiple function calls.
You are tasked with merging multiple source objects into a single target object, ensuring that properties from the latest source overwrite those in the target. Which operator would you use, and how would you apply it to accomplish this task?
- Object.assign(target, ...sources);
- target << sources;
- target.merge(sources);
- target.spread(...sources);
To merge multiple source objects into a single target object in JavaScript and ensure that properties from the latest source overwrite those in the target, you would use the Object.assign() method. The ...sources syntax spreads the source objects into the Object.assign() method, accomplishing the task efficiently. The other options are not valid for this operation.
The concept of Non-Blocking I/O in Node.js is primarily built around the ________ paradigm.
- Asynchronous
- Synchronous
- Blocking
- Multithreading
The concept of Non-Blocking I/O in Node.js is primarily built around the "Asynchronous" paradigm. It allows I/O operations to occur without waiting for each other, enhancing efficiency and responsiveness in handling multiple requests concurrently.