When securing a web application using JWT, implementing ________ helps in mitigating the risk of token interception.
- Token expiration
- Strong encryption
- Public key authentication
- Rate limiting
When securing a web application with JWT (JSON Web Tokens), implementing strong encryption is crucial to mitigate the risk of token interception. Encryption ensures that the token's content remains confidential even if intercepted. Token expiration (Option 1) deals with token validity periods, while public key authentication (Option 3) is related to how JWT signatures are verified. Rate limiting (Option 4) is a measure to control access but doesn't directly address token interception.
What is the first line of defense against injection attacks in web applications?
- Using a web application firewall (WAF).
- Escaping user input before displaying it.
- Using strong authentication mechanisms.
- Regularly updating server software.
The first line of defense against injection attacks in web applications is to escape or sanitize user input before displaying it on web pages. This prevents malicious code from being executed, protecting against common injection attacks like SQL injection and cross-site scripting (XSS).
What considerations should be made when deciding between using a mock and a stub in a test case?
- The complexity of the test scenario
- The need for recording method calls
- The desire to control method behavior
- The size of the test data
When deciding between using a mock and a stub in a test case, considerations should include the complexity of the test scenario, as mocks are generally more complex than stubs. Recording method calls is a characteristic of mocks, and controlling method behavior is a characteristic of stubs. The size of the test data is typically not directly related to choosing between mocks and stubs.
You are tasked with implementing a secure authentication system for a web application. What considerations should you make to ensure the security of user credentials and session information?
- Store passwords in plain text
- Use a secure hashing algorithm for password storage
- Use HTTP for transmitting sensitive data
- Keep session tokens in local storage
To ensure the security of user credentials and session information, you should use a secure hashing algorithm (like bcrypt) to store passwords, not store them in plain text. Additionally, sensitive data should not be transmitted over HTTP, and session tokens should be stored securely (not in local storage, which is vulnerable to cross-site scripting attacks).
You are developing a Node.js application that should gracefully shut down when it receives a termination signal. How would you accomplish this using the process object?
- process.on('terminate', () => { /* Graceful shutdown code */ });
- process.kill('SIGTERM', process.pid);
- process.exit(0);
- process.handleTermination(() => { /* Graceful shutdown code */ });
To gracefully shut down a Node.js application upon receiving a termination signal, you should use process.on('terminate', () => { /* Graceful shutdown code */ });. This registers an event handler for the 'terminate' event. The other options either do not handle termination signals gracefully or are incorrect syntax.
How can you optimize the performance of a SQL query that reads a large amount of data?
- Use indexes on columns frequently queried.
- Avoid joins and subqueries.
- Increase the page size of the database.
- Fetch all data at once to minimize network latency.
To optimize the performance of a SQL query reading large data, you should use indexes on columns frequently queried. Indexes improve data retrieval speed. The other options may not necessarily lead to performance improvements and can even degrade performance.
How can you implement template inheritance in Pug?
- extend layout.pug
- include layout.pug
- inherit layout.pug
- template layout.pug
In Pug, template inheritance is implemented using the extend keyword followed by the name of the layout file. This allows child templates to inherit the structure and content of the specified layout file. The other options (include, inherit, and template) are not used for template inheritance in Pug.
When designing systems with Non-Blocking I/O, careful consideration must be given to avoid ________, where multiple asynchronous operations are competing for resources.
- Callback Hell
- Deadlock
- Blocking I/O
- Synchronous Execution
When designing systems with Non-Blocking I/O, careful consideration must be given to avoid "Callback Hell," also known as "Callback Pyramid" or "Callback Spaghetti." This occurs when multiple asynchronous operations are nested deeply, making code difficult to read and maintain.
What does the process object in Node.js primarily provide information about?
- Operating system processes
- Web browser processes
- File I/O processes
- Database processes
The process object in Node.js primarily provides information about operating system processes. It allows you to interact with and control the Node.js process, such as accessing command line arguments, environment variables, and exiting the process. It is not related to web browser, file I/O, or database processes.
You are tasked with creating tests for a complex system with multiple interacting components. How would you decide which components to mock or stub to achieve a balance between test isolation and reliability?
- Mock all components to ensure complete isolation
- Stub only the most complex components
- Mock components that are external or slow
- Stub components that are stable and well-tested
When testing a complex system, it's essential to strike a balance between test isolation and reliability. Mocking all components can lead to over-fragmented tests and make maintenance difficult. Stubbing only the most complex components may not ensure adequate coverage. To achieve this balance, you should mock components that are external or slow, as these can introduce variability and slow down tests. Stubbing components that are stable and well-tested can help reduce unnecessary complexity and speed up test execution.
The else if statement is used in JavaScript for ________.
- conditional execution
- error handling
- multiple comparisons
- branching based on multiple conditions
The else if statement in JavaScript is used for branching based on multiple conditions. It allows you to check additional conditions if the previous if condition is false.
How does npm handle version conflicts between dependencies and devDependencies?
- It prioritizes devDependencies over dependencies
- It prioritizes dependencies over devDependencies
- It raises a version conflict error
- It automatically resolves conflicts
npm prioritizes dependencies over devDependencies. If there's a version conflict between a package listed in dependencies and the same package listed in devDependencies, the version specified in dependencies takes precedence. This ensures that the application uses the expected versions during production deployment.