Node.js

When a javaScript function is invoked (called) in Node, where is a new frame placed?

**Explanation:** From javascripttutorial: [reference](https://www.javascripttutorial.net/javascript-call-stack/#:~:text=If%20a%20function%20calls%20another,top%20of%20the%20call%20stack.)

1.

the call stack

2.

the event loop

3.

the poll phase

4.

the events queue

Q 1 / 68

Node.js

Which of the following is a core module in Node?

**Explanation:** From flaviocopes docs: [reference](https://flaviocopes.com/node-core-modules/)

1.

webpack

2.

crypto

3.

request

4.

chalk

Q 2 / 68

Node.js

Which of the following Buffer class methods returns an uninitialized buffer?

**Explanation:** From official docs: [reference](https://nodejs.org/dist/latest-v13.x/docs/api/buffer.html#buffer_class_method_buffer_allocunsafe_size)

1.

allocUnsafe

2.

concat

3.

from

4.

alloc

Q 3 / 68

Node.js

Which of the following modules is NOT a built-in module in Node?

**Explanation:** From flaviocopes docs: [reference](https://flaviocopes.com/node-core-modules/)

1.

ftp

2.

events

3.

dgram

4.

http2

Q 4 / 68

Node.js

Which fs module method can be used to read the content of a file without buffering it in memory?

**Explanation:** _From official docs: [reference](https://nodejs.org/api/fs.html#fs_dir_read) To minimize memory costs, when possible prefer streaming via fs.createReadStream()._

1.

read

2.

readFile

3.

createReadStream

4.

readFileSync

Q 5 / 68

Node.js

Which of the following DNS module methods uses the underlying OS facilities and does not necessarily perform any network communication?

**Explanation:** From official docs: [reference](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback)

1.

lookup

2.

resolve

3.

resolve4

4.

reverse

Q 6 / 68

Node.js

How do you check that a value is a date object in Node?

**Explanation:** From official docs: [reference](https://nodejs.org/api/util.html#util_util_types_isdate_value)

1.

util.types.isDate(value)

2.

assert.isDate(value)

3.

console.isDate(value)

4.

util.date(value)

Q 7 / 68

Node.js

Can you create an https web server with Node.js?

**Explanation:** From official docs: [reference](https://nodejs.dev/learn/making-http-requests-with-nodejs)

1.

no, there are no modules supporting it yet

2.

yes, with the https or http2 modules

3.

yes, through the path module

4.

yes, with the http module

Q 8 / 68

Node.js

What is the Api that is designed to insulate Addons from changes in the underlying JavaScript engine?

**Explanation:** From official docs: [reference](https://nodejs.org/api/n-api.html#n_api_node_api)

1.

A-API

2.

Z-API

3.

N-API

4.

X-API

Q 9 / 68

Node.js

Which CLI option can you use to debug a node script in Chrome DevTools?

**Explanation:** From official docs: [reference](https://nodejs.org/en/docs/guides/debugging-getting-started/)

1.

--dev-tools

2.

--inspect

3.

--chrome

4.

--debug

Q 10 / 68

Node.js

How can you count the number of logical CPUs on the machine that is running Node?

**Explanation:** From coderrocketfuel docs: [reference](https://coderrocketfuel.com/article/get-the-number-of-system-cpu-cores-using-node-js)

1.

node -p "process.cpus"

2.

node -p "util.cpus().size"

3.

node -p "process.os.cpus"

4.

node -p "os.cpus().length"

Q 11 / 68

Node.js

Which of the following is a method on the console object?

**Explanation:** From official docs: [reference](https://nodejs.org/api/console.html)

1.

exit

2.

test

3.

time

4.

print

Q 12 / 68

Node.js

Which object is used to manage the cache of required modules?

**Explanation:** From official docs: [reference](https://nodejs.org/api/modules.html#modules_require_cache)

1.

global.cache

2.

module.cache

3.

process.cache

4.

require.cache

Q 13 / 68

Node.js

What is the command to silence all process warnings?

**Explanation:** From official docs: [reference](https://nodejs.org/api/cli.html#cli_no_warnings)

1.

node index.js --trace-warnings

2.

node --no-warnings

3.

node -trace-warnings

4.

node index.js --no-warnings

Q 14 / 68

Node.js

How can you use the promise API with a callback-based function such as child_process.exec?

**Explanation:** From official docs: [reference](https://nodejs.org/api/child_process.html)

1.

new Promise(child_process.exec())

2.

util.promisify(child_process.exec())

3.

util.promisify(child_process.exec)

4.

new Promise(child_process.exec)

Q 15 / 68

Node.js

Which of the following is NOT a Node repl command?

**Explanation:** From official docs: [reference](https://nodejs.org/api/repl.html#repl_commands_and_special_keys)

1.

.break

2.

.history

3.

.editor

4.

.save

Q 16 / 68

Node.js

Which statement is true when you run the code shown below?

`require('child_process').fork('script.js');` **Explanation:** From official docs: [reference](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)

1.

The forked process shares the event loop with the parent process

2.

A new VM instance is created and the two VM instances will be shared between the forked process and the parent process.

3.

The forked process will have its own VM instance.

4.

The forked process shares the same VM thread with the parent process.

Q 17 / 68

Node.js

If EventEmitter is in scope, which of the following lines of code will have an event emitter emitting a change event?

**Explanation:** _Because the EventEmitter is already in scope. No need to create new one._

1.

EventEmitter.emit('change');

2.

EventEmitter.new().emit('change');

3.

(new EventEmitter()).emit('change');

4.

new EventEmitter('change');

Q 18 / 68

Node.js

Which of the following objects is a stream

**Explanation:** _process.stdout is Buffer type._

1.

process.uptime

2.

process.stdout

3.

process

4.

Buffer

Q 19 / 68

Node.js

Which module variable holds the resolved absolute path of the current module file?

#### 21. If the child_process module methods are in scope, what is a current way to execute the command ps -ef using a child process?

1.

`__pathname`

2.

`__location`

3.

`__flder`

4.

`__filename`

5.

spawn("ps -ef")

6.

exec("ps -ef")

7.

exec("ps", "-ef")

8.

fork("ps -ef")

Q 20 / 68

Node.js

undefined

1.

stack

2.

trace

3.

debug

4.

print

Q 21 / 68

Node.js

undefined

1.

the libuv library

2.

the c-ares library

3.

the VM (like VS or Chakra)

4.

the repl module

Q 22 / 68

Node.js

undefined

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 Worldn"); }); server.listen(port, hostname, () => { console.log(`server running at http://${hostname}:${port}/`); });

1.

server running at http://localhost:3000/

2.

server running at port 3000

3.

server running at http://localhost:4000/

4.

server running at http://127.0.0.1:3000/

Q 23 / 68

Node.js

undefined

1.

to provide utilities to play with file and directory paths

2.

to provide utilities to add and remove files

3.

It is a retiring module.

4.

to provide utilities to test files

Q 24 / 68

Node.js

undefined

1.

server. start

2.

server.activate

3.

server.listen

4.

server. run

Q 25 / 68

Node.js

undefined

const fs = require('fs'); const os = require('os'); const system = os.platform(); const user = os.userInfo().username; fs.appendFile('hello.txt', `Hello ${user} on ${system}`, (err) => { if (err) throw err; console.log('The data was appended to file!');} );

1.

creates a text file hello.txt and appends customized text

2.

creates an image file

3.

console logs system information

4.

creates a file named data and append numbers

Q 26 / 68

Node.js

undefined

1.

nodemon start

2.

start index.js

3.

node index.js

4.

node start

Q 27 / 68

Node.js

undefined

1.

to provide methods to work with requests and responses

2.

to provide methods to work with files

3.

to provide methods to work with databases

4.

to find new file systems

Q 28 / 68

Node.js

undefined

1.

It is the current unstable version and is to be avoided.

2.

It is the version that will be retired soon.

3.

It is the version with the latest features.

4.

It is the safest version for long-term support.

Q 29 / 68

Node.js

undefined

1.

process. stdinfo

2.

process. stdin

3.

process. stdout

4.

process. stderr

Q 30 / 68

Node.js

undefined

`console.log(arguments);`

1.

ReferenceError: arguments is not defined

2.

an empty string

3.

undefined

4.

an object representing an array that has five elements

Q 31 / 68

Node.js

undefined

1.

start

2.

on

3.

once

4.

off

Q 32 / 68

Node.js

undefined

1.

process

2.

Buffer

3.

root

4.

require

Q 33 / 68

Node.js

undefined

1.

node index.js -x

2.

node -v

3.

node -h

4.

node index.js -h

Q 34 / 68

Node.js

undefined

1.

http.IncomingMessage

2.

http.ServerRequest

3.

http.ClientRequest

4.

http.ServerResponse

Q 35 / 68

Node.js

undefined

1.

`exports, __filename, __dirname`

2.

`exports, process, require, module, __filename, __dirname`

3.

`exports, module, __filename, __dirname`

4.

`exports, require, module, __filename, __dirname`

Q 36 / 68

Node.js

undefined

1.

V8

2.

c-ares

3.

libuv

4.

events

Q 37 / 68

Node.js

undefined

1.

a C++ file that can have a .node extension and that Node will be able to execute directly.

2.

a C++ Addon file that is built with node-gyp

3.

a JSON file that can have a .node extension as well as the .json extension

4.

a JavaScript file that can have a .node extension as well as the .js extension

Q 38 / 68

Node.js

undefined

1.

only objects.

2.

only functions

3.

only variables and arrays

4.

functions, objects, arrays, or anything you assign to the module

Q 39 / 68

Node.js

undefined

1.

os

2.

util

3.

cluster

4.

net

Q 40 / 68

Node.js

undefined

1.

SSL

2.

hash

3.

crypto

4.

TLS

Q 41 / 68

Node.js

undefined

1.

const { readFile } = require(fs).promises

2.

const { readFile } = require(fs)

3.

const { readFilePromises: readFile } = require(fs)

4.

const { readFile } = require(promises)

Q 42 / 68

Node.js

undefined

1.

Changes are not backwards compatible.

2.

Changes might not be backward compatible and might break existing code.

3.

Changes are just bug fixes and no new features were added.

4.

Changes will add new functionality but will not break any existing code.

Q 43 / 68

Node.js

undefined

1.

run, examine, put, loop

2.

read, eval, print, loop

3.

run, edit, print, loop

4.

read, extend, print, loop

Q 44 / 68

Node.js

undefined

1.

.gyprc

2.

binding.gyp

3.

gyp.json

4.

package.gyp

Q 45 / 68

Node.js

undefined

1.

chai

2.

jest

3.

assert

4.

mocha

Q 46 / 68

Node.js

undefined

1.

cluster

2.

async_hooks

3.

dgram

4.

inspector

Q 47 / 68

Node.js

undefined

1.

buffer

2.

util

3.

string_decoder

4.

string_buffer

Q 48 / 68

Node.js

undefined

**Explanation:** _process is an global object and act like a bridge, the others aren't 1. [source](https://nodejs.org/api/globals.html) 2. [source](https://nodejs.org/api/process.html#process_process)

1.

v8

2.

env

3.

process

4.

child_process

Q 49 / 68

Node.js

undefined

**Explanation:** _https://www.geeksforgeeks.org/why-node-js-is-a-single-threaded-language/_

1.

Every Node process runs in a single thread, and all the I/O work is run in that same thread.

2.

Every Node process gets four threads that it can share between its JavaScript VM and the event loop.

3.

The event loop is single-threaded, but a JavaScript VM can use multiple threads.

4.

JavaScript execution in Node.js is single-threaded, but I/O operations are executed using multiple threads.

Q 50 / 68

Node.js

undefined

1.

Event names must be camelCase strings.

2.

The emit method allows a arbitrary set of arguments to be passed to the listener functions.

3.

Any values returned by the listeners for an emitted events are ignored.

4.

When an event emitter objeect emits an event, all of the functions attached to that specific event are called synchronously.

Q 51 / 68

Node.js

undefined

1.

sandbox

2.

buffer

3.

vm

4.

v8

Q 52 / 68

Node.js

undefined

**Explanation:** _From official docs: [https://nodejs.org/api/cluster.html#cluster_cluster](https://nodejs.org/api/cluster.html#cluster_cluster)_

1.

const numInstances = cluster.instances().length;

2.

const numInstances = cluster.instances();

3.

const numInstances = require('os').cpus().length;

4.

const numInstances = process.cpus().length;

Q 53 / 68

Node.js

undefined

**Explanation:** _From official docs: [https://nodejs.org/api/readline.html#readline_example_read_file_stream_line_by_line](https://nodejs.org/api/readline.html#readline_example_read_file_stream_line_by_line)_

1.

Use regular expressions directly on the file.

2.

Use Promises and async/await to offload the task to libuv.

3.

Copy the file into a database and perform the operations there.

4.

Use readline together with streams to read and transform and write the file contents line by line.

Q 54 / 68

Node.js

undefined

**Explanation:** _process, exports and setTimeout are global objects, Buffer isn't (please see https://nodejs.org/api/globals.html)_

1.

process

2.

exports

3.

setTimeout

4.

Buffer

Q 55 / 68

Node.js

undefined

1.

readableStream.pipe(writableStream)

2.

readableStream.on(pipe, writableStream)

3.

writableStream.pipe(readableStream)

4.

writableStream.on(pipe, readableStream)

Q 56 / 68

Node.js

undefined

1.

path.concat

2.

path.join

3.

path.format

4.

path.parse

Q 57 / 68

Node.js

undefined

1.

to allow users to make requests to the server

2.

to insulate Addons from changes in the underlying JavaScript engine

3.

to execute multi-threaded code in the Node environment

4.

to provide a quick way for users to create REST APIs

Q 58 / 68

Node.js

undefined

1.

a locally scoped object that provides information about the current node process

2.

a global object that provides information about files

3.

a global object that provides information about the database

4.

a global object that provides information about the current node process

Q 59 / 68

Node.js

undefined

// File: person.js exports.name = "Jane"; // File: index.js const person = require('./person.js'); console.log(person);

1.

`{'Jane'}`

2.

`{ name: 'Jane' }`

3.

`{}`

4.

`Jane`

Q 60 / 68

Node.js

undefined

// File: person.js exports = "John"; // File: index.js const person = require('./person.js'); console.log(person);

1.

`John`

2.

`Undefined`

3.

`{'John'}`

4.

`{}`

Q 61 / 68

Node.js

undefined

**From the article:** [Making a Testing Framework in Node.js (Without any External Libraries)](https://www.sohamkamani.com/blog/javascript/making-a-node-js-test-runner/)

1.

yes, through the assert module

2.

yes, through the debugger module

3.

yes, through the console module

4.

no

Q 62 / 68

Node.js

undefined

1.

fail

2.

doesNotThrow

3.

deepStrictEqual

4.

ifError

Q 63 / 68

Node.js

undefined

1.

promisify

2.

asyncify

3.

types

4.

callbackify

Q 64 / 68

Node.js

undefined

1.

GlobalError

2.

TypeError

3.

RangeError

4.

AssertionError

Q 65 / 68

Node.js

undefined

1.

Python

2.

V8 JavaScript engine

3.

PHP

4.

c

Q 66 / 68

Node.js

undefined

1.

As Node.js is asynchronous, this is handled by a libuv and a threadpool. The performance will not notably degrade.

2.

As the application code runs asynchronously within a single thread, the execution will block, accepting no more requests until the operation is completed.

3.

As Node.js is asynchronous, this is handled by a threadpool and the performance will not notably degrade.

4.

The current thread will block until the executon is completed and the operating system will spawn new threads to handle incoming requests. This can exhaust the number of allowed threads (255) and degrade performance over time.

Q 67 / 68

Node.js

undefined

1.

EventLoop

2.

Libuv

3.

Google V8

4.

Express.js

Q 68 / 68