0% found this document useful (0 votes)
5 views

Node.js Quizes

The document provides an overview of Node.js, including its definition, the engine it uses, and concepts like REPL. It covers various JavaScript features such as the spread operator, destructuring assignment, and the async keyword, as well as Node.js server functionalities like the listen() method and event loop phases. Additionally, it discusses Express.js, middleware usage, and MVC pattern in applications.

Uploaded by

ptlshanaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Node.js Quizes

The document provides an overview of Node.js, including its definition, the engine it uses, and concepts like REPL. It covers various JavaScript features such as the spread operator, destructuring assignment, and the async keyword, as well as Node.js server functionalities like the listen() method and event loop phases. Additionally, it discusses Express.js, middleware usage, and MVC pattern in applications.

Uploaded by

ptlshanaya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Section 1 :

1. What is node.js? - A JS runtime - allows JS to be run on server.


2. Which engine is used to run node.js? - Chrome v8 engine.
3. What is REPL - Read, Eval, Print & Loop.We use files instead of REPL.

Section 2:

1. What does … operator do in JS?


A. It is used to spread iterables to individual elements
B. It is used to describe a datatype of undefined size
C. No such operator exists
D. None of the above

2. What is the purpose of destructuring assignment in ES6?


A. To assign a value to a variable.
B. To split an array or object into individual variables.
C. To access the properties of an object.
D. To define default values for variables.

3. What is the purpose of the async keyword in JavaScript?


A. To declare a function as asynchronous.
B. To define an array of values.
C. To create a new object.
D. To fetch data from a remote server.

Section 3:

4. Which of the following accurately describes the role of a web server in the client-server
model?
A. A web server sends requests to the client for data.
B. A web server renders web pages using HTML and CSS.
C. A web server hosts and serves web pages to clients upon request.
D. A web server manages client-side scripting languages like JavaScript.

5. What is the purpose of the listen() method in the context of Node.js web servers?
A. To start the server and begin accepting requests.
B. To terminate the server and stop accepting requests.
C. To specify the port number for the server.
D. To define routes and handle incoming requests.

6. When creating a Node.js server, which method is typically used to specify how the server
should respond to different URL paths?
A. setPath()
B. handleRoute()
C. onRoute()
D. createServer()
7. What happens if a blocking synchronous operation is performed in a Node.js application?
A. It will not affect the event loop, as Node.js automatically handles blocking operations.
B. It will cause the event loop to be blocked until the operation completes.
C. It will be executed asynchronously in the background.
D. It will result in an error and terminate the Node.js process.

8. In the Node.js event loop, what is the purpose of the "Poll" phase?
A. To execute I/O operations such as reading from files
B. To handle callbacks for setTimeout() and setInterval() functions
C. To perform tasks related to the network communication
D. To process callbacks registered with process.nextTick()

Section 4:

9. Which command is used to initialize a new Node.js project and create a package.json file?
A. npm init
B. npm install
C. npm start
D. npm config

10. What is the purpose of the node_modules directory in a Node.js project?


A. It contains the source code of the project.
B. It stores configuration files for npm packages.
C. It holds the installed dependencies of the project.
D. It is used for caching npm packages during installation.

11.Which command is used to uninstall a package using npm?


A. npm remove package-name
B. npm uninstall package-name
C. npm delete package-name
D. npm purge package-name

12. Which method is commonly used to throw a custom error in Node.js?


A. throwError()
B. raiseError()
C. createError()
D. throw new Error()

13. What is an Error object in Node.js?


A. A built-in object that represents a runtime error in JavaScript code
B. An object that stores information about the user's session on the server
C. An object that encapsulates information about the HTTP request received by the
server
D. An object that defines custom error types for handling specific types of errors
Section 5:

14. What is Express.js?


A. A front-end JavaScript framework for building interactive user interfaces.
B. A relational database management system (RDBMS) commonly used with Node.js.
C. A web application framework for Node.js, designed for building web applications and
APIs.
D. A task runner tool used for automating repetitive tasks in Node.js development.

15. In an Express.js application, where are middlewares typically defined?


A. Inside the app.listen() function
B. Within the server.js file
C. Inside the package.json file
D. Before or after route handlers using the app.use() function

16. What is the purpose of mounting middleware at a specific path in Express.js?


A. To restrict access to certain routes based on user permissions
B. To organize middleware functions and route handlers into modular components
C. To handle errors that occur during the execution of middleware functions
D. To optimize performance by caching responses for specific routes

17. What is the typical syntax for defining a middleware function in Express.js?
A. function middleware(req, res, next) { // middleware logic }
B. middleware(req, res, next) => { // middleware logic }
C. middleware = (req, res, next) => { // middleware logic }
D. function(req, res, next) { // middleware logic }

18.How can you export an Express Router instance for use in other modules?
A. By calling the export function and passing the router object as an argument
B. By assigning the router object to module.exports
C. By calling the module.export() function with the router object as an argument
D. By requiring the router module and calling its exported functions within other modules

19. What is the purpose of using router.param() in Express Router?


A. To define route parameters that are passed in the URL
B. To parse incoming request data and populate req.params with the parsed values
C. To define middleware functions that are executed for specific route parameters
D. To configure route-specific settings such as access control and rate limiting

20. What types of request bodies can body-parser parse by default in Express.js?
A. JSON only
B. URL-encoded form data only
C. JSON and URL-encoded form data
D. XML and plain text
Section 7:

21. In an Express.js application following the MVC pattern, where might you typically find
route definitions and request handling logic?
A. In the model layer
B. In the view layer
C. In the controller layer
D. In the middleware layer

You might also like