NodeJS QB
NodeJS QB
js
Q1. When a javaScript function is invoked (called) in Node, where is a new frame
placed?
the call stack
the event loop
the poll phase
the events queue
Explanation: From javascripttutorial: reference
Q2. Which of the following is a core module in Node?
webpack
crypto
request
chalk
Explanation: From flaviocopes docs: reference
Q3. Which of the following Buffer class methods returns an uninitialized buffer?
allocUnsafe
concat
from
alloc
Explanation: From official docs: reference
Q4. Which of the following modules is NOT a built-in module in Node?
ftp
events
dgram
http2
Explanation: From flaviocopes docs: reference
Q5. Which fs module method can be used to read the content of a file without
buffering it in memory?
read
readFile
createReadStream
readFileSync
Explanation: From official docs: reference To minimize memory costs, when possible
prefer streaming via fs.createReadStream().
Q6. Which of the following DNS module methods uses the underlying OS facilities
and does not necessarily perform any network communication?
lookup
resolve
resolve4
reverse
Explanation: From official docs: reference
Q7. How do you check that a value is a date object in Node?
util.types.isDate(value)
assert.isDate(value)
console.isDate(value)
util.date(value)
Explanation: From official docs: reference
Q8. Can you create an https web server with Node.js?
no, there are no modules supporting it yet
yes, with the https or http2 modules
yes, through the path module
yes, with the http module
Explanation: From official docs: reference
Q9. What is the Api that is designed to insulate Addons from changes in the
underlying JavaScript engine?
A-API
Z-API
N-API
X-API
Explanation: From official docs: reference
Q10. Which CLI option can you use to debug a node script in Chrome DevTools?
--dev-tools
--inspect
--chrome
--debug
Explanation: From official docs: reference
Q11. How can you count the number of logical CPUs on the machine that is running
Node?
node -p "process.cpus"
node -p "util.cpus().size"
node -p "process.os.cpus"
node -p "os.cpus().length"
Explanation: From coderrocketfuel docs: reference
Q12. Which of the following is a method on the console object?
exit
test
time
print
Explanation: From official docs: reference
Q13. Which object is used to manage the cache of required modules?
global.cache
module.cache
process.cache
require.cache
Explanation: From official docs: reference
Q14. What is the command to silence all process warnings?
node index.js --trace-warnings
node --no-warnings
node -trace-warnings
node index.js --no-warnings
Explanation: From official docs: reference
Q15. How can you use the promise API with a callback-based function such as
child_process.exec?
new Promise(child_process.exec())
util.promisify(child_process.exec())
util.promisify(child_process.exec)
new Promise(child_process.exec)
Explanation: From official docs: reference
Q16. Which of the following is NOT a Node repl command?
.break
.history
.editor
.save
Explanation: From official docs: reference
Q17. Which statement is true when you run the code shown below?
require('child_process').fork('script.js');
The forked process shares the event loop with the parent process
A new VM instance is created and the two VM instances will be shared between
the forked process and the parent process.
The forked process will have its own VM instance.
The forked process shares the same VM thread with the parent process.
Explanation: From official docs: reference
Q18. If EventEmitter is in scope, which of the following lines of code will have an
event emitter emitting a change event?
EventEmitter.emit('change');
EventEmitter.new().emit('change');
(new EventEmitter()).emit('change');
new EventEmitter('change');
Explanation: Because the EventEmitter is already in scope. No need to create new
one.
Q19. Which of the following objects is a stream
process.uptime
process.stdout
process
Buffer
Explanation: process.stdout is Buffer type.
Q20. Which module variable holds the resolved absolute path of the current
module file?
__pathname
__location
__flder
__filename
Q21. If the child_process module methods are in scope, what is a current way to
execute the command ps -ef using a child process?
spawn("ps -ef")
exec("ps -ef")
exec("ps", "-ef")
fork("ps -ef")
Reference: From official docs: reference
Q22. Which console method can be used to print the stack trace to the point of its
execution?
stack
trace
debug
print
Q23. When you run JavaScript in a Node.js application, which of the following
elements in a Node.js stack actually executes that JavaScript?
the libuv library
the c-ares library
the VM (like VS or Chakra)
the repl module
Q24. Looking at the code below, what does the console show?
const http = require('http');
const hostname = '127.0.0.1'; const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200; res.setHeader("Content-Type", "text/plain");
res.end("Hello World\n");
});
server.listen(port, hostname, () => { console.log(`server running at
http://${hostname}:${port}/`); });
// File: index.js
const person = require('./person.js');
console.log(person);
{'Jane'}
{ name: 'Jane' }
{}
Jane
// File: index.js
const person = require('./person.js');
console.log(person);
John
Undefined
{'John'}
{}
Refrence
Q80. Which choice is not a Node global object?
process
exports
setTimeout
Buffer
Refrence