wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Node.js

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the main advantage of using asynchronous programming in Node.js?

a)

Limited scalability

b)

Synchronous execution

c)

Non-blocking I/O operations

d)

Increased complexity

2.

Explain the concept of RESTful APIs in one sentence.

a)

A set of rules and constraints for communication between systems over HTTP.

b)

A protocol for transferring files between systems

c)

A programming language used to build APIs

d)

A method for securing APIs using encryption keys

3.

How can you handle errors in Node.js applications?

a)

Implement try-catch blocks, promises with .catch(), event emitters, and error middleware in Express.js

b)

Ignore errors and hope for the best

c)

Manually restart the server every time an error occurs

d)

Use Python instead of Node.js

4.

Name one security best practice when working with Node.js applications.

a)

Ignore security vulnerabilities

b)

Implement input validation

c)

Use outdated libraries

d)

Disable logging

5.

What is the role of the 'next' function in middleware?

a)

To terminate the middleware chain

b)

To return an error message

c)

To skip the current middleware function

d)

To pass control to the next middleware function in the stack.

6.

How can you prevent SQL injection attacks in Node.js applications?

a)

Use parameterized queries with prepared statements, input validation, and sanitize user inputs.

b)

Trust all user inputs without any sanitization

c)

Ignore input validation and directly execute user inputs

d)

Use plain text queries without any validation

7.

What is the purpose of the 'body-parser' middleware in Node.js?

a)

It sends the request body to a remote server

b)

It parses the incoming request body and makes it available under req.body property.

c)

It encrypts the request body for security purposes

d)

It generates random data for the request body

8.

How can you securely store sensitive information such as API keys in Node.js applications?

a)

Use environment variables and dotenv package

b)

Use a plain text file to store API keys

c)

Save API keys in a public GitHub repository

d)

Store API keys directly in code

9.

What is the significance of the 'req' and 'res' objects in middleware functions?

a)

The 'req' object is used for database queries

b)

The 'req' object represents the server's response

c)

The 'res' object represents the HTTP request

d)

The 'req' object represents the HTTP request and the 'res' object represents the HTTP response.

10.

What is the purpose of using 'helmet' middleware in Node.js applications?

a)

To enhance security by setting various HTTP headers to protect against web vulnerabilities.

b)

To improve performance by caching static assets

c)

To handle user authentication and authorization

d)

To automatically generate API documentation