NODEJS MCQ

Q.1 The _________ is used to get a list of files and directories in the current directory.

cd

ls

pwd

None of above

Q.2 Which command is used to print the current working directory?

cd

ls

pwd

None of above

Q.3 Write command to move the directory one level up from the current directory.

cd

ls

cd ..

None of above

Q.4 Node uses _________ engine in core.

SpiderMonkey

Microsoft Chakra

Chrome V8

Node En

Q.5 Node.js is capable of asynchronous I/O requests.

False

True

Q.6 Simple or complex functionality organized in a single or multiple JavaScript files which can be reused throughout your Node.js application is called ________.

Module

Library

Package

Function

Q.7 How Node.js modules are made available externally?

module.exports

module.expose

module.imports

module.spread

None of the above

Q.8 Which function is used to include modules and libraries in Node Js?

include();

require();

attach();

None of the above

Q.9 Which command will be used to set up a new or existing package?

node init

node create

npm init

npm create

Q.10 package.json contains the metadata and project dependencies of Node project?

False

True

Q.11 We can run multiple Node.js servers on a single machine.

False

True

Q.12

var http = require("http");

var http = new require("http");

var http = new server();

none of the above

Q.13 Which among these will run our server on port 3000.

const http = require('http'); const port = 3000; const server = http.createServer(); server.listen(port, function(err){ console.log("Server is up and running on port:", port); });

const http = require('http'); const port = 3000; const server = http.newServer(); server.listen(port, function(err){ console.log("Server is up and running on port:", port); });

const http = require('http'); const port = 3000; const server = http.createServer(); server.start(port, function(err){ console.log("Server is up and running on port:", port); });

const http = require('http'); const port = 3000; const server = createServer(); server.listen(port, function(err){ console.log("Server is up and running on port:", port); });

Q14.Which HTTP status code signifies the client does not have access rights to the content, the server is refusing to give the requested resource. You can visit the following link for exploring different HTTP Status codes.

401

403

402

404

Q.15 Which of these sends a Response HTTP Status Code 200 to the browser?

res.sendHeader(200, {'content-type': 'text/html'});

res.write(200, {'content-type': 'text/html'});

res.writeHead(200, {'content-type': 'text/html'});

res.writeHeader(200, {'content-type': 'text/html'});

Q.16 Which of the following modules can be used for file specific operations?

path

fs

http

None of the above

Q.17 If a file named 'file.txt' exists and an error occurred while reading a file using the code below-

fs.readFile('./file.txt', (err, data)=>{ if(err) {
console.log("Inside gets printed.");
}
console.log("Outside gets printed.");
});
What will be the output shown in the terminal/console?

Inside gets printed.

Outside gets printed.

Inside gets printed. Outside gets printed. None of the above

error occurs and gets printed on the console

Q.18 What is true about 'appendFile' function of 'fs' module?

It overwrites the data already stored in the file

Creating the file if it does not yet exist

Copies data from a source file and appends that data to a destination file

None of the above

Q.19 What is the first parameter of the callback function inside the 'readFile' function of 'fs' module?

Data of the file

Error

Any of the two

None of them

Q.20 How to get the requested URL, if req is the request variable.

req.url()

req.url

req.get(url);

req.get(url());

Q.21 Which command will install nodemon globally?

node install nodemon

node install -g nodemon

npm install -g nodemon

npm install nodemon

Q.22 The code below is used to select the file to display according to the requested URL .-

Suppose you have assigned port number: 8000)
switch(request.url) {
case '/home':
filePath = './index.html';
break;
case '/profile':
filePath = './profile.html';
break;
default:
filePath = './404.html';
}
What will happen if the URL -‘127.0.0.1: 8000' gets hit?

'index.html' file gets displayed on the browser

'profile.html' file gets displayed in the browser

'404.html' file gets displayed in the browser

the code will not work, so nothing is displayed in the browser

Q.23 Is Express the only framework for Node.js?

Yes

No

Q.24 What is the extended name for MVC?

Model Visual Control

Model Visual Controller

Model View Controller

None of the above

Q.25 package.json contains all the dependencies required by express.

True

False

Q.26 What are core features of Express framework?

Allows to set up middlewares to respond to HTTP Requests

Defines a routing table which can work as per HTTP Method and URL

Dynamically render HTML Pages

All of the above

Q.27 What does the 'node_modules' folder contain?

Libraries that Node.js requires

Contains the application structure

Libraries that Express requires

None of the above

Q.28 Which command will install express in your project?

node install express

node install -g express

node install express save

npm install express

Q.29 _________ gives the the directory name of the current module.

dirname

__dirname

module

module_name

Q.30 ________ prints the value of x into the ejs template (HTML)

<% x %>

<%_ x %>

<%= x %>

<%# x %>

Q.31 The _____________ attribute specifies a short hint that describes the expected value of an input field.

type

placeholder

input

name

Q.32 The _________ attribute is acts as a key for the value entered in the input element, when the form is submitted and data is received at the server.

type

placeholder

input

name

Q.33 Which among these are the task that a middleware function can perform?

Execute any code.

Make changes to the request and the response objects.

End the request-response cycle

Call the next middleware function in the stack.

All of the Above

Q.34 What will get printed in the console if http://localhost:8000/ is visited and these are the middlewares defined in index.js?

app.use(function(req, res, next){
console.log('middleware 1 called');
});
app.use(function(req, res, next){
console.log('middleware 2 called');
next();
});
app.use(function(req, res, next){
console.log('middleware 3 called');
next();
});

middleware 1 called

middleware 1 called middleware 2 called

middleware 1 called middleware 2 called middleware 3 called

None of the Above

Q.35 Query params can be used to send multiple query parameters?

True

False

Q.36 If the query submitted to the server is
http://localhost:8001/delete-contact/?phone=123456789&name=Coding%20Ninjas And this is the method delete-contact

app.get('/delete-contact/', function(req, res){
console.log(req.query.phone);
console.log(req.query.name);
return res.redirect('back');
}
What will get printed in the console?

123456789 Coding Ninjas

123456789 Coding%20Ninjas

123456789 Undefined

phone: '12131321321' name: 'Coding Ninjas'

None of the Above

Q.37 Which of the following is not a NoSQL database ?

MongoDB

SqLite 3

Firebase

None of the Above

Q.38 Under which category of NoSql do mongoDB falls?

Wide Column Stores

Document databases 

Graph databases

None of the Above

Q.39 Which among these statements will make a connection to the database ‘contactlistdb’ running on localhost when we’re using mongoose?

mongoose.connect('contact_list_db');

mongoose.connect('mongodb://localhost/contact_list_db');

mongoose.connection('mongodb://localhost/contact_list_db');

mongoose.connect('localhost/contact_list_db');

Q.40 Select all the valid schema types in MongoDB.

String

Number

Date

Integer

Boolean

Mixed

Float

ObjectId

Array

Q.41 _____is a property set on each document when first created by Mongoose.

id

type

versionkey

None of the Above

Q.42 Which of the following systems record changes to a file in a project over time?

Record Control

Code Control

Version Control

None of the mentioned

Q.43 Which of the following adds all the changes in files for staging?

git add .

git add -u

git add new

None of the Above

Q.44 Which of the following command allows you to update the remote repository?

push

add

update

None of the Mentioned

Q.45 Select the statement which can be used to create a route handlers.

var router = express.Router()

let router = express.Router()

var router = express.newRouter()

var router = Router()

Q.46 By default express routing is case sensitive.

True

False

Q.47 /foo and /foo/ are treated the same by the express router.

True

False

Q.48 Write the command to install layouts.

npm install express-ejs-layouts

npm i ejs

npm i express-layout

npm i express-ejs-layout

Q.49 The static files should be kept inside _______ folder.

Assets

Config

Models

Routes

Q.50 _________ is validating your credentials like User Name/User ID and password to verify your identity.

Authorization

Authentication

Q.51 ___________ is the process of verifying that you have access to something, such as gaining access to a resource.

Authentication

Authorization

Q.52 Cookies can be altered by the server.

True

False

Q.53 Which of these is not a passport.js strategy

passport-github

passport-twitter

passport-local

passport-facebook

passport-ninjas

Q.54 Passport.js is a middleware

False

True

Q.55 Why did we use express-sessions

To create a session cookie

To store the logged in user’s information in an encrypted format in the cookie

To make the server run faster

Q.56 Without Mongo Store, this was the problem we faced

User was logged in even after refresh

User was logged out after every server restart

Sign in page was inaccessible

Sign out page was visible

Q.57 Sign out is basically

Deleting a user from the database

Replacing the user’s session cookie with a dummy one to fake the identity of the user

Resetting the user’s password

Removing the user’s session cookie to remove the identity

Q.58 These are the formats for SASS

1. SCSS
2. Indented
3. Quoted
4. French

1

1 and 2

3

3 and 4

Q.59 Browsers understand SCSS

True

False

Q.61 Choose One to Many relation examples

Student : Class

Book : Author

Date : Week

Train : User

Q.62 Choose Many to Many relation examples

Student : Class

Book : Author

Date : Week

Train : User

Q.63 Choose One to One relation examples

Student : Class

Book : Author

Date : Week

Train : User

Q.64 How will we get all the posts of a user if we have the user’s id (user_id) from our current schema

Post.where({id: user_id}, function(err, post){})

Post.find({user: user_id}, function(err, post){})

Post.findByIdAndUpdate({user: user_id}, function(err, post){})

Q.65 The following query deletes all users with age > 10

User.findByIdAndDelete(10, function(err){console.log(‘deleted’);});

User.deleteOne({age: 10}, function(err){console.log(‘deleted’);});

User.deleteMany({age: 10, function(err){console.log(‘deleted’);});

User.deleteMany({age: {$gte: 10}, function(err){console.log(‘deleted’);});

Q.66 While fetching all comments from the DB, which of these will populate user of the comment and post of the comment

Comment.find({}).populate(‘user’, ‘post’).exec()

Comment.find({}).populate(‘user, post’).exec()

Comment.find({}).populate(‘user’).populate(‘post’).exec()

Q.67 While fetching all posts from the DB, which command will populate the comments in that post and the user of each of the comments

Post.find({}).populate(‘user’, ‘comment, user’).exec();

Post.find({}).populate(‘user’).populate({path: ‘comments’, populate: {path: ‘user’}}).exec();

Post.find({}).populate(‘comments’).populate(‘user’).exec();

Q.68 Let’s assume there’s a user ‘A’ who has written a post. User ‘B’ cannot delete that post, only user ‘A’ can. This is:

Authorization

Authentication

Verification

Confirmation

Q.69 The following query deletes all users with age > 10

User.findByIdAndDelete(10, function(err){console.log(‘deleted’);});

User.deleteOne({age: 10}, function(err){console.log(‘deleted’);});

User.deleteMany({age: 10, function(err){console.log(‘deleted’);});

User.deleteMany({age: {$gte: 10}, function(err){console.log(‘deleted’);});

Q.70 How to send context {content: “My first post”} specifically to a partial called ‘_post.ejs’?

a) <%- include("_post", {content: “My first post”}) %>
b) It gets passed from the parent template

Only a is correct

Only b is correct

Both a and b are correct

None of the above

Q.71 Difference between user.id and user._id

They are the same

user.id gets the string of user._id and user._id is of type ObjectId

Q.72 User.findOneAndUpdate will find a user and update the record. Which option, if passed t will create a new User object if User.findOneAndUpdate is unable to find a user

{insert : true}

{create_new: true}

{Upsert: true}

Q.73 Mongoose queries are ______ by default?

Asynchronous

Synchronous

Promises

Difficult

Q.74 Async Await simplifies the following?

a) Behaviour of using promises synchronously
b) Callback hell
c) Execution of async code
d) All of the above

a,c

a,b

b,d

b,c

Q.75 Connect-flash needs __________ and ________ middleware to be able to store flash messages

a) node-sass-middleware
b) express-session
c) cookie-parser
d) Passport

a,b

b,c

c,d

d,a

Q.76 Connect-flash stores flash messages in session-cookies

False

True

Q.77 Libraries which can be used to implement flash messages with Express

a) express-flash-messages
b) connect-flash
c) session-flash
d) Express-flash-2

a,b,c

a,b,d

a,c,d

b,c,d

Q.78 Which of these is not a value of ‘type’ option in Noty

alert

important

success

Info

Q.79 Which of the following middleware code will stop the server from sending a response to the browser

a. function(req, res, next){
res.locals.flash = {
success: req.flash('success'),
error: req.flash('error')
}
next();
}
b. function(req, res, next){
res.locals.flash = {
success: req.flash('success'),
error: req.flash('error')
}
}

a

b

Q.80 What type of request does AJAX send to the server by default?/h3>

XMLHttpRequest (XHR)

JavaScript

HTML

CSS

Q.81 What format are we using to communicate with the server with AJAX requests

XML

JSON

C++

HTML

Q.82 AJAX can be used for?

Uploading files to the server

Submitting a form and sending that data to the server

Dynamically adding content to a web page using JavaScript from JSON received from the server

All of the above

Q.83 Which of these will serialize the data from an html form with id=”new-post-form”

$(‘#new-post-form’).serialize()

var data = new FormData(document.getElementById(‘new-post-form’))

JSON.stringify($(‘#new-post-form’))

None of the above

Q.84 How to check if a request is XHR in express (when request is being accessed by a variable ‘req’)

req.json

req.xhr

res.status

res.send

Q.85 Which of these will tell the browser according to HTTP status codes that the request is unauthorized?

res.status(200).json({data: {post_id: req.params.id}, message: "Unauthorized"});

res.status(404).json({data: {post_id: req.params.id}, message: "Unauthorized"});

res.status(500).json({data: {post_id: req.params.id}, message: "Unauthorized"});

res.status(401).json({data: {post_id: req.params.id}, message: "Unauthorized"});

Q.86 _____ method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.

Date.second()

Date.now()

Date.Exit()

Date.Time()

Q.87 It is necessary to add attribute enctype="multipart/form-data" to the form tag in order to upload files.

False

True

Q.89 What are the options that can be passed to multer?

destination or storage fileFilter

limits

preservePath

All of the Above

None of the Above

Q.89 The _________ options determine within which folder the uploaded files should be stored.

destination

filename

landing

None of the Above

Q.90 The default value of Field Name Size is

2000

100 bytes

1MB

Infinity

Q.91 Through APIs following can be done -

Requesting Data from the Database

Getting a response back from Application

Changing the functions of the Application

None

Q.92 Postman is a _____.

Chrome Extension

Web Application

Native Application

All of the above are correct

Q.93 What does JWT stands for?

Javascript Web Token

Javascript Web Terminal

JSON Web Token

None of the Above

Q.94 Passport-JWT stores User object in request headers.

True

False

Q.95 Extracting the JWT from the request

_____ method creates a new extractor that looks for the JWT in the authorization header with the scheme 'bearer'. You can go through this link to explore more about different methods available in passport-jwt.
https://www.npmjs.com/package/passport-jwt

fromAuthHeaderAsBearerToken()

Q.96 The secret key used in password-jwt-strategy.js is 'codeial', _____ will set the token and send it to the user.

jwt.sign(user.toJSON(), 'codeial')

jwt.signIn(user.toJSON(), 'codeial', { expiresIn: '1000' })

jwt.sign(toJSON(), secret-key, { expiresIn: '1000' })

None of the Above

Q.97Before using passport-google-oauth20, you must register an application with Google.

False

True

Q.98 In Google OmniAuth Oauth2, we enter the origin of our app in _______ field.

Authorized JavaScript origins

Authorized Redirect URL

Authorized Javascript Start

None of the Above

Q.99 The callbackUrl is also known as

Authorized JavaScript origins

Authorized Redirect URL

Authorized Javascript Start

None of the Above

Q.100 A _________ is a special kind of token that can be used to obtain a renewed access token

Access Token

Refresh Token

Reload Token

None of the Above

Q.101 Different Mail protocols and Mail protocol extensions are

SMTP

POP3

FTP

MIME

IMAP

HTTP

Q.102 The Default port number for SMTP is

25

26

587

None of the Above

Q.103 SMTP over SSL/TLS works over port ____

25

26

587

None of the Above

Q.104 ________ is the authentication object in the transporter.

authenticator

auth

authentication

credentials

None of the Above

Q.105 The _____ function is used to send mail

mailTo()

sendMail()

transportMail()

None of the Above

Q.106 _______ is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability.

kue

redis

queue

None of the Above

Q.107 By using _______ Mongoose will look at the onModel property to find the right model dynamically.

ref: ‘onModel’

refPath: ‘onModel’

reference: ‘onModel’

None of the above

Q.108 Which among these will delete all the likes associated with the comments in a post, if a post is deleted.

Like.deleteMany(likeable: post, onModel: ‘Post’);

Like.deleteMany(id: {$in: post.comments});

Q.109 _____ is a technique by which the client keeps asking the server for new data regularly.

polling

Q.110 The _____ pattern defines a one to many dependency between objects so that one object changes state, all of its dependents are notified and updated automatically.

Observer

Subscriber

Q.111 _____ event is fired when a new connection is fired

connect

connection

newConncetion

None of the Above

Q.112 _____ adds the client to the room

sockets.addUser(room_name)

sockets.addClient(room_name)

sockets.join(room_name)

None of the Above

Q.113 Environment Variables are needed for?

Globally accessible values/commands

Hiding secure data from the developer

All of the above

Q.114 Production Logs can be viewed live

False

True

Q.115 Why do we need to add an extra hash along the name of optimized assets

To make the file names unique

To prevent the browser from caching if the asset is already present in the browser

It just looks more technical

It’s not important

Q.116 What all are the alternatives to Gulp

Redux

Webpack

Grunt

None, Gulp is unique

Q.117 What port is used to SSH into our remote Ubuntu Machine?

1

22

333

4444

Q.118 What is the technical term of our server running in background

Lemon mode

Background mode

Daemon mode

BG Mode

Q.119 NGINX can be used for serving the content of multiple websites from the same machine

False

true

Q.120 NGINX can be used to create a load balancer

False

True

Q.121 Which DNS record do we need to change to mask our cloud machine’s IP address with the domain name?

TXT

DNS

A

AA

Q.122 The static files should be kept inside _______ folder.

Assets

Config

Models

Routes

Q.123 How to check equality of two Nodejs ?

==

===

isEqual()

isEqualNode()

Q.124 How many Node object methods are available?

18

20

22

24

Q.125 What is the use of underscore variable in REPL session?

To get the last used command

to get the last result

to store the result

None

Q.126 Which module is used to serve static files in Node.js?

static

node-static

http

node-http

Q.127 Which of the following are Node.js stream types?

Duplex

All of the above

Readable

Writable

Q.

Q.

Q.

Q.

Q.

Q.