- Node.js Tutorial
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
- Node.js Useful Resources
- Node.js - Quick Guide
- Node.js - Useful Resources
- Node.js - Dicussion
Node.js Mock Test
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.
Node.js Mock Test II
Q 1 - Buffer class is a global class and can be accessed in application without importing buffer module.
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?
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?
Answer : A
Explanation
buf.length returns size of a node buffer in bytes.
Q 4 - Which of the following is true about readable stream?
A - Readable stream is used for read operation.
B - Output of readable stream can be input to a writable stream.
Answer : C
Explanation
Readable stream is used for read operation and its output can be input to a writable stream.
Q 5 - Which of the following is true about writable stream?
A - writable stream is used for write operation.
B - Output of readable stream 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.
Q 6 - Which of the following is true about Piping streams?
A - Piping is a mechanism where we provide output of one stream as the input to another stream.
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.
Q 7 - Which of the following is true about Chaining streams?
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?
Answer : A
Explanation
Require directive is used to load a Node module(fs) and store returned its instance(fs) into its variable(fs).
Q 9 - Which of the following is true about File I/O in Node applications?
A - Node implements File I/O using simple wrappers around standard POSIX functions.
B - Node File System (fs) module should be imported for File I/O opearations.
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.
Q 10 - Which of the following is true about fs module of Node?
A - Every method in fs module have synchronous as well as asynchronous form.
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.
Q 11 - Which method of fs module is used to open a file?
A - fs.open(path, flags[, mode], callback)
B - fs.openFile(path, flags[, mode], callback)
Answer : A
Explanation
fs.open(path, flags[, mode], callback) is the method which is used to open a file.
Q 12 - Which method of fs module is used to get information about file?
A - fs.open(path, flags[, mode], callback)
Answer : B
Explanation
fs.stat(path, callback) is the method which is used to get information about a file.
Q 13 - Which method of fs module is used to read a file?
A - fs.open(path, flags[, mode], callback)
B - fs.openFile(path, flags[, mode], callback)
Answer : D
Explanation
fs.read(fd, buffer, offset, length, position, callback) is the method which is used to read a file.
Q 14 - Which method of fs module is used to write a file?
A - fs.write(path, flags[, mode], callback)
B - fs.writeFile(path, flags[, mode], callback)
Answer : B
Explanation
fs.writeFile(path, flags[, mode], callback) is the method which is used to write a file.
Q 15 - Which method of fs module is used to close a file?
B - fs.closeFile(fd, callback)
Answer : A
Explanation
fs.close(fd, callback) is the method which is used to close a file.
Q 16 - Which method of fs module is used to truncate a file?
A - fs.delete(fd, len, callback)
B - fs.remove(fd, len, callback)
Answer : C
Explanation
fs.ftruncate(fd, len, callback) is the method which is used to truncate a file.
Q 17 - Which method of fs module is used to delete a file?
A - fs.delete(fd, len, callback)
Answer : C
Explanation
fs.unlink(path, callback) is the method which is used to delete a file.
Q 18 - Which method of fs module is used to read a directory?
A - fs.readDirectory(path[, mode], callback)
B - fs.read(path[, mode], callback)
Answer : C
Explanation
fs.readdir(path, callback)is the method which is used to read a directory.
Q 19 - Which method of fs module is used to remove a directory?
A - fs.deleteDirectory(path[, mode], callback)
Answer : B
Explanation
fs.rmdir(path, callback) is the method which is used to remove a directory.
Q 20 - Which of the following is true about global objects in Node applications?
A - Global objects are global in nature and they are available in all modules.
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.
Q 21 - Which of the following is true about __filename global object?
A - The __filename represents the filename of the code being executed.
B - The __filename represents the resolved absolute path of code file.
Answer : C
Explanation
The __filename represents the filename of the code being execute
Q 22 - Which of the following is true about __dirname global object?
B - The __dirname represents the resolved absolute path of code file.
Answer : A
Explanation
The __dirname represents the name of the directory that the currently executing script resides in.
Q 23 - Which of the following is true about setTimeout(cb, ms) global function?
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.
Q 24 - Which of the following is true about clearTimeout(t) global function?
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.
Q 25 - Which of the following is true about setInterval(cb, ms) global 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 |