Advanced Node.js test (Advanced)
40 questions · 40 minutes · Free
Event loop internals, streams, clustering, performance and security.
Take the Advanced Node.js test
What it covers
- Event loop phases and libuv
- Streams and backpressure
- Worker threads and clustering
- Memory leaks and profiling
- API security and NestJS
Interview format
- Questions: 40 questions — 24 multiple choice, 12 multi-answer, 4 predict-the-output
- Time: 40 minutes, timed from the first question
- Difficulty: Advanced
- Skill area: Backend
- Price: Free
Earn a certificate
The Advanced Node.js test is one of the 8 tests of the Backend Developer: Advanced learning path. Pass it and the other 7 tests at 70% or more and readyforhires issues you a verifiable certificate in your name, with its own code and verify link to share or add to LinkedIn.
Sample questions
5 sample questions from the Advanced Node.js test, with the answers. Samples are taken out of the live test, so you will not meet these when you sit it.
When reading a stream in Node.js and no encoding is explicitly defined, what is the default encoding that may lead to a common mistake if the actual data uses a different format?
- Base64
- UTF-8
- Hex
- ASCII
Answer: B. UTF-8
When using streams in Node.js, the default encoding for string-based streams is UTF-8. If a developer assumes a different encoding (like ASCII or Base64), it can lead to incorrect data interpretation or encoding errors. It's important to explicitly set the encoding when needed, but UTF-8 is the default and most commonly used encoding in modern applications.
What is the behavior of the cluster module in Node.js when it comes to load balancing and distributing incoming connections?
- The cluster module creates multiple worker processes that each listen on separate ports, and the primary process distributes incoming connections in a round-robin fashion.
- The cluster module creates multiple worker processes that each listen on separate ports, and the primary process distributes incoming connections based on the least connections algorithm.
- The cluster module creates multiple worker processes that share the same port, and the primary process distributes incoming connections to the workers based on the least connections algorithm.
- The cluster module creates multiple worker processes that share the same port, and the primary process distributes incoming connections to the workers in a round-robin fashion.
Answer: D. The cluster module creates multiple worker processes that share the same port, and the primary process distributes incoming connections to the workers in a round-robin fashion.
The cluster module in Node.js is designed to create multiple worker processes that share the same port. The primary process (master) listens on the port and distributes incoming connections to the worker processes in a round-robin fashion by default. This allows for efficient load balancing across multiple CPU cores. The other options are incorrect because they either misrepresent the behavior of the cluster module or describe unrelated concepts.
In a realistic project scenario, how should a system enforce JWT token expiration to ensure expired tokens are not accepted?
- Store the token's expiration time in the database for later checks.
- Verify the token's expiration time (exp claim) during request processing.
- Ignore the expiration time and rely on session management instead.
- Allow the token to expire automatically without any checks.
Answer: B. Verify the token's expiration time (exp claim) during request processing.
In a realistic project scenario, JWT token expiration is enforced by verifying the 'exp' claim in the token during request processing. This ensures that expired tokens are not accepted by the system. Other options may relate to token creation or storage, but not the actual enforcement of expiration during a request.
What happens when you pipe a readable stream to a writable stream in Node.js?
- The data is written to the destination stream only after the source stream has finished reading all the data from its source.
- The source stream reads all the data from its source first and then writes it to the destination stream in one batch.
- The data is written to the destination stream as soon as it is available, and the source stream continues to read from the source until it ends.
- The source stream pauses until the destination stream is ready to receive more data, but the data is not written until the destination is ready.
Answer: C. The data is written to the destination stream as soon as it is available, and the source stream continues to read from the source until it ends.
When piping between streams in Node.js, the source stream reads data from its source and writes it to the destination stream. The destination stream processes the data as it is received. This behavior is managed internally by Node.js, and backpressure is handled automatically to ensure the source stream does not overwhelm the destination stream.
Which of the following best describes how libuv handles I/O operations compared to an alternative approach?
- libuv handles I/O operations asynchronously using an event loop, while the alternative (such as synchronous I/O) allows other operations to run concurrently.
- libuv handles I/O operations synchronously, while the alternative (such as asynchronous I/O) blocks the thread until the operation completes.
- libuv handles I/O operations synchronously, while the alternative (such as asynchronous I/O) allows other operations to run concurrently.
- libuv handles I/O operations asynchronously using an event loop, while the alternative (such as synchronous I/O) blocks the thread until the operation completes.
Answer: D. libuv handles I/O operations asynchronously using an event loop, while the alternative (such as synchronous I/O) blocks the thread until the operation completes.
libuv uses asynchronous I/O to avoid blocking the main thread, making it efficient for non-blocking operations. Synchronous I/O, on the other hand, blocks the thread until the operation is complete, which can lead to poor performance in applications requiring high concurrency. libuv's approach is ideal for scalable and responsive applications, while synchronous I/O is better suited for simple or low-concurrency scenarios.
Frequently asked questions
- How many questions are in the Advanced Node.js test?
- 40 questions (24 multiple choice, 12 multi-answer, 4 predict-the-output), with 40 minutes to answer them.
- What does the Advanced Node.js test cover?
- Event loop phases and libuv, Streams and backpressure, Worker threads and clustering, Memory leaks and profiling, API security and NestJS.
- Is the Advanced Node.js test free?
- Yes. It is free to take with a readyforhires account.
- What level is the Advanced Node.js test?
- Advanced, in Backend.