wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding MVC and Express.js

Total questions: 16

Worksheet time: 8mins

Name
Class
Date
1.

What does MVC stand for in software architecture?

a)

Model-View-Controller

b)

Model-View-Component

c)

Main-View-Controller

d)

Module-View-Creator

2.

Which component of MVC is responsible for handling user input?

a)

View

b)

Model

c)

Controller

d)

Database

3.

In Express.js, what is the purpose of middleware functions?

a)

Middleware functions are used to connect databases in Express.js.

b)

Middleware functions are responsible for rendering HTML pages in Express.js.

c)

Middleware functions handle user authentication in Express.js.

d)

The purpose of middleware functions is to process requests and responses in the Express.js application.

4.

How do you define a route in Express.js?

a)

app.get('/path', (req, res) => { res.send('Hello World!'); });

b)

app.route('/path', (req, res) => { res.send('Goodbye World!'); });

c)

app.post('/path', (req, res) => { res.send('Hello World!'); });

d)

app.get('/anotherPath', (req, res) => { res.send('Hello World!'); });

5.

What is the role of the Model in MVC architecture?

a)

The Model defines the visual layout of the application in MVC architecture.

b)

The Model routes requests to the appropriate controllers in MVC architecture.

c)

The Model handles user interface elements in MVC architecture.

d)

The Model manages the data and business logic in MVC architecture.

6.

Which HTTP method is typically used to create a new resource in a RESTful API?

a)

DELETE

b)

PATCH

c)

POST

d)

PUT

7.

What is an ORM and how does it relate to databases?

a)

An ORM is a database management system that stores data in XML format.

b)

An ORM is a tool that facilitates the interaction between an application and a database by mapping objects to database tables.

c)

An ORM is a type of database that only supports NoSQL data models.

d)

An ORM is a programming language used to create database queries directly.

8.

What is the purpose of a controller in the MVC pattern?

a)

The purpose of a controller in the MVC pattern is to handle user input and update the model and view accordingly.

b)

The controller manages the database connections and queries.

c)

The controller is responsible for rendering the HTML templates.

d)

The controller handles the server configuration and deployment.

9.

How can you handle errors in Express.js middleware?

a)

Define an error-handling middleware with four parameters: (err, req, res, next).

b)

Use console.log to display errors in the console.

c)

Ignore errors and continue to the next middleware.

d)

Return a 404 status for all errors in middleware.

10.

What is the difference between PUT and POST in RESTful APIs?

a)

PUT and POST are interchangeable methods for creating resources in RESTful APIs.

b)

PUT deletes a resource at a specific URI; POST updates a resource at a defined URI.

c)

PUT updates or creates a resource at a specific URI; POST creates a resource at a server-defined URI.

d)

PUT creates a resource at a server-defined URI; POST updates or creates a resource at a specific URI.

11.

What is the purpose of the 'next' function in Express.js middleware?

a)

The 'next' function allows middleware to pass control to the next function in the stack.

b)

The 'next' function sends a response to the client directly.

c)

The 'next' function terminates the middleware process immediately.

d)

The 'next' function is used to log requests to the console.

12.

How do you define relationships between models in an ORM?

a)

Models are linked using indexes and naming conventions.

b)

Relationships are established through primary keys and data types.

c)

Relationships are defined using foreign keys and relationship methods in an ORM.

d)

Associations are created with unique identifiers and validation rules.

13.

What is a RESTful API and what principles does it follow?

a)

A RESTful API is a database management system that uses SQL queries.

b)

A RESTful API is a programming language for building web applications.

c)

A RESTful API is a type of software that requires a specific operating system.

d)

A RESTful API is an architectural style for networked applications that uses standard HTTP methods and follows principles like statelessness, client-server architecture, uniform interface, resource-based interactions, and layered system.

14.

How can you serve static files in an Express.js application?

a)

Implement 'app.use('/files', express.static('uploads'))' for the 'uploads' directory.

b)

Use 'app.get('/static', express.static('assets'))' to serve files from 'assets'.

c)

Set 'app.static('public')' to serve static content from the 'public' folder.

d)

Use 'app.use(express.static('public'))' to serve static files from the 'public' directory.

15.

What is the significance of the 'req' and 'res' objects in Express.js?

a)

The 'req' object is for handling incoming request data, while the 'res' object is for sending responses back to the client.

b)

The 'req' object manages session data, while the 'res' object is for database connections.

c)

The 'req' object is used for routing, and the 'res' object is for logging errors.

d)

The 'req' object is for sending responses, while the 'res' object handles incoming requests.

16.

How do you validate data in an Express.js application?

a)

Use middleware like 'express-validator' or 'Joi' to define and enforce validation rules.

b)

Rely on database constraints for data integrity.

c)

Implement client-side validation only with JavaScript.

d)

Use built-in Node.js methods for data validation.