Script Valley
Node.js: The Complete Runtime
Async JavaScript in Node.js/Assessment

Practice & Assessment

Test your understanding of Async JavaScript in Node.js

Multiple Choice Questions

5
1

What is the difference between Promise.all and Promise.allSettled?

2

Why does awaiting inside a for loop run iterations sequentially instead of in parallel?

3

What is the recommended action inside a process.on('uncaughtException') handler?

4

Which code snippet correctly runs three file reads in parallel using async/await?

5

What does emitter.once('event', handler) do differently from emitter.on('event', handler)?

Coding Challenges

1
1

Async File Merger with Error Handling

Write an async function mergeTextFiles(inputPaths, outputPath) that reads all files listed in inputPaths in parallel using Promise.all, concatenates their contents separated by a newline, and writes the result to outputPath. Handle the case where any input file does not exist by logging a warning and skipping that file without failing the whole operation. Input: array of file paths and an output path string. Output: written file and a console summary showing how many files were merged vs skipped. Estimated time: 25 minutes.

Medium

Mini Project

1

Event-Driven File Processor

Build a FileProcessor class that extends EventEmitter. It must: accept a directory path in the constructor; expose a start() method that reads all .txt files in that directory; emit a 'file' event for each file with {name, content, wordCount}; emit a 'done' event when all files are processed with a summary {totalFiles, totalWords}; emit an 'error' event if the directory does not exist or a file cannot be read. Process files in parallel using Promise.all. Write a script that creates a FileProcessor, registers listeners for all events, and calls start(). Test with at least three .txt files in a directory.

Medium