Node.js Mock Test


Advertisements

This section presents you various set of Mock Tests related to Node.js Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Node.js Mock Test II

Q 1 - Buffer class is a global class and can be accessed in application without importing buffer module.

A - true

B - false

Answer : A

Explanation

Buffer class is a global class and can be accessed in application without importing buffer module.

Q 2 - Which of the following code converts a buffer buf to JSON object?

A - buf.toJSON()

B - buf.json()

C - buf.covertToJson()

D - buf.jsonify()

Answer : A

Explanation

buf.toJSON() converts a buffer buf to JSON object.

Q 3 - Which of the following code gets length of a buffer buf?

A - buf.length

B - buf.size

C - buf.length()

D - buf.size()

Answer : A

Explanation

buf.length returns size of a node buffer in bytes.

Answer : C

Explanation

Readable stream is used for read operation and its output can be input to a writable stream.

Answer : C

Explanation

Writable stream is used for write operation and it can take output of readable stream as input.

Answer : D

Explanation

Piping is a mechanism where we provide output of one stream as the input to another stream. It is normally used to get data from one stream and to pass output of that stream to another stream. There is no limit on piping operations.

Answer : C

Explanation

Chanining is a mechanism to connect output of one stream to another stream and create a chain of multiple stream operations. It is normally used with piping operations.

Q 8 - Which of the following statement is valid to use a Node module fs in a Node based application?

A - var fs = require("fs");

B - var fs = import("fs");

C - package fs;

D - import fs;

Answer : A

Explanation

Require directive is used to load a Node module(fs) and store returned its instance(fs) into its variable(fs).

Answer : C

Explanation

Node implements File I/O using simple wrappers around standard POSIX functions. Node File System (fs) module should be imported for File I/O opearations.

Answer : C

Explanation

Every method in fs module have synchronous as well as asynchronous form. Asynchronous methods of fs module take last parameter as completion function callback and first parameter of the callback function as error.

Answer : A

Explanation

fs.open(path, flags[, mode], callback) is the method which is used to open a file.

Answer : B

Explanation

fs.stat(path, callback) is the method which is used to get information about a file.

Answer : D

Explanation

fs.read(fd, buffer, offset, length, position, callback) is the method which is used to read a file.

Answer : B

Explanation

fs.writeFile(path, flags[, mode], callback) is the method which is used to write a file.

Answer : A

Explanation

fs.close(fd, callback) is the method which is used to close a file.

Answer : C

Explanation

fs.ftruncate(fd, len, callback) is the method which is used to truncate a file.

Answer : C

Explanation

fs.unlink(path, callback) is the method which is used to delete a file.

Answer : C

Explanation

fs.readdir(path, callback)is the method which is used to read a directory.

Answer : B

Explanation

fs.rmdir(path, callback) is the method which is used to remove a directory.

Answer : C

Explanation

Node.js global objects are global in nature and they are available in all modules. We do not need to include these objects in our application, rather we can use them directly.

Answer : C

Explanation

The setTimeout(cb, ms) global function is used to run callback cb after at least ms milliseconds. The actual delay depends on external factors like OS timer granularity and system load. A timer cannot span more than 24.8 days. This function returns an opaque value that represents the timer which can be used to clear the timer.

Answer : A

Explanation

The clearTimeout( t ) global function is used to stop a timer that was previously created with setTimeout(). Here t is the timer returned by setTimeout() function.

Answer : C

Explanation

The setInterval(cb, ms) global function is used to run callback cb repeatedly after at least ms milliseconds. The actual delay depends on external factors like OS timer granularity and system load. - A timer cannot span more than 24.8 days. This function returns an opaque value that represents the timer which can be used to clear the timer using the function clearInterval(t).

Answer Sheet

Question Number Answer Key
1 A
2 A
3 A
4 C
5 C
6 D
7 C
8 A
9 C
10 C
11 A
12 B
13 D
14 B
15 A
16 C
17 C
18 C
19 B
20 C
21 C
22 A
23 C
24 A
25 C
nodejs_questions_answers.htm
Advertisements