Node.js Test 1 — Questions and Answers
Question 1: When there is no more data to read, the stream sends an end event.
- False
- True (Correct answer)
Correct answer: True
Explanation: <br> When there is no more data to read, a stream fires an end event.
Question 2: Which of the following statements concerning the global object __dirname is correct?
- The _dirname represents the resolved absolute path of code file
- The _dirname represents the name of the directory that the currently executing script rides in. (Correct answer)
- none of these
Correct answer: The _dirname represents the name of the directory that the currently executing script rides in.
Explanation: <br> The __dirname specifies the name of the directory in which the currently running script is located.
Question 3: Which of the following lines of code prints the amount of memory used?
- console.log('Current version: ' + process.getMemory());
- console.log('Current version: ' + process.getMemory());
- console.log('Current version: ' + process.memory()); (Correct answer)
- none of these
Correct answer: console.log('Current version: ' + process.memory());
Explanation: <br> To find out how much memory is being consumed, use process.memoryUsage().
Question 4: Which of the following statements regarding Node.JS is correct?
- Node.js is used to develop I/O intensive web application like video streaming sites, single page applications and other web application
- Node.js is open source and is completely free to use
- Node.js is a JavaScript based framework/platform built on Google Chrome's JavaScript V8 Engine
- All of these (Correct answer)
Correct answer: All of these
Explanation: <br> Node.js is a powerful JavaScript-based framework/platform based on the JavaScript V8 Engine in Google Chrome. It is used to develop I/O-intensive online applications such as video streaming sites, single-page applications, and other websites. Thousands of developers use Node.js because it is open source and absolutely free.
Question 5: Which of the following statements concerning the global function setTimeout(cb, ms) is true?
- The setTimeout(cb, ms) functions returns to opaque value that represents the timer which can be clear the timer
- The setTimeout(cb, ms) global function is used to run callback cb after at least ms milliseconds
- Both of the above (Correct answer)
- None of these
Correct answer: Both of the above
Explanation: <br> The global function setTimeout(cb, ms) is used to perform callback cb after at least ms milliseconds. The real delay is determined by external factors such as the granularity of the OS timer and the system load. A timer can only run for 24.8 days. The timer is represented by an opaque value returned by this function, which can be used to clear the timer.
Question 6: Which of the following statements concerning the child process module's spawn method is correct?
- The spawn() metod returns streams (stdout, stderr)
- The spawn() method launches a new process with a given command
- Both of the above (Correct answer)
- None of these
Correct answer: Both of the above
Explanation: <br> The spawn() method returns streams after launching a new process with a supplied command (stdout, stderr).
Question 7: Which of the following statements regarding the EventEmitter.on property is correct?
- on property is used to locate an event handler
- on property is used to fire event
- on property is used to bind a function with the event (Correct answer)
- none of these
Correct answer: on property is used to bind a function with the event
Explanation: <br> The event's on property is used to bind a function to it.
Question 8: Which of the following statements regarding Chaining Streams is correct?
- Chanining is normally used with piping operations
- Chanining is a mechanism to connect output of one stream to another stream and create chain of multiple stream operations
- Both of the above (Correct answer)
- None of these
Correct answer: Both of the above
Explanation: <br> Chanining is a method of connecting the output of one stream to the output of another stream in order to build a chain of multiple stream operations. It's most commonly associated with piping operations.
Question 9: Which of the following statements concerning external binding in terms of domain modules is correct?
- Error Emmitter is added explicitly to domain using its add method (Correct answer)
- Error emmitter is executing its code with run method to domain
- Both of the above
- None of these
Correct answer: Error Emmitter is added explicitly to domain using its add method
Explanation: <br> In the case of external binding, the error emitter is explicitly added to a domain using its add method.
When there is no more data to read, the stream sends an end event.