wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Node.js and Express Fundamentals

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is Node.js primarily used for?

a)

Developing mobile games

b)

Creating desktop applications

c)

Designing static websites

d)

Building scalable network applications and web servers.

2.

Which of the following is a core module in Node.js?

a)

http

b)

path

c)

events

d)

fs

3.

What does Express.js provide for Node.js applications?

a)

A command-line tool for managing Node.js packages

b)

A template engine for rendering HTML

c)

A database management system for Node.js

d)

Express.js provides a web application framework for Node.js, enabling routing, middleware, and easy handling of HTTP requests.

4.

What is middleware in Express?

a)

Middleware is a front-end framework

b)

Middleware in Express is a function that processes requests and responses.

c)

Middleware is a programming language

d)

Middleware is a type of database

5.

How do you install Express in a Node.js project?

a)

Execute 'npm install express.js' in your project directory.

b)

Run 'npm install express' in your project directory.

c)

Use 'npm add express' in your project folder.

d)

Run 'npm start express' in your project directory.

6.

Which method is used to read a file synchronously in Node.js?

a)

fs.readFileAsync

b)

fs.readFile

c)

fs.readFileSync

d)

fs.readSync

7.

What is the purpose of the 'fs' module in Node.js?

a)

The 'fs' module is for creating web servers in Node.js.

b)

The 'fs' module is used for file system operations in Node.js.

c)

The 'fs' module is used for network operations in Node.js.

d)

The 'fs' module handles database connections in Node.js.

8.

How do you define a route in Express?

a)

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

b)

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

c)

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

d)

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

9.

What is the default port for an Express application?

a)

3000

b)

5000

c)

8080

d)

4000

10.

What command is used to start a Node.js application with nodemon?

a)

nodemon

b)

npm run

c)

nodemon start

d)

node

11.

How can you serve static files in an Express application?

a)

Set 'app.staticFiles('path/to/static/files');' to serve static files.

b)

Implement 'app.serveStaticFiles('path/to/static/files');' to serve static files.

c)

Use 'app.get('/static', express.static('path/to/static/files'));' to serve static files.

d)

Use 'app.use(express.static("path/to/static/files"));' to serve static files.

12.

What is the purpose of the 'app.use()' method in Express?

a)

To define routes in an Express application.

b)

To mount middleware functions in an Express application.

c)

To handle HTTP requests directly.

d)

To serve static files in an Express application.

13.

How do you handle errors in Express middleware?

a)

Ignore errors and continue processing requests.

b)

Use an error-handling middleware function with four parameters (err, req, res, next) to handle errors in Express.

c)

Use console.log to display errors in the terminal.

d)

Return a generic error message without details.

14.

What is the function of the 'req' and 'res' objects in Express routes?

a)

The 'req' object sends the response, while the 'res' object receives the request.

b)

The 'req' object is used for logging, and the 'res' object is for error handling.

c)

The 'req' object manages database connections, while the 'res' object formats HTML.

d)

The 'req' object handles the request data, while the 'res' object manages the response to the client.

15.

How can you read a JSON file using the 'fs' module?

a)

const fs = require('fs'); fs.readFile('file.json', 'utf8', (data) => { console.log(data); });

b)

const fs = require('fs'); fs.readFile('file.json', 'utf8', (err, data) => { if (err) throw err; const jsonData = JSON.parse(data); console.log(jsonData); });

c)

const fs = require('fs'); fs.readFile('file.json', (data) => { console.log(data); });

d)

const fs = require('fs'); fs.readFileSync('file.json');

16.

What is the purpose of the 'body-parser' middleware in Express?

a)

To handle routing in Express applications.

b)

To serve static files in Express applications.

c)

To manage database connections in Express.

d)

To parse incoming request bodies in Express applications.

17.

How do you define a GET route in Express?

a)

app.delete('/route', (req, res) => { res.send('Response'); });

b)

app.put('/route', (req, res) => { res.send('Response'); });

c)

app.get('/route', (req, res) => { res.send('Response'); });

d)

app.post('/route', (req, res) => { res.send('Response'); });

18.

What is the command to install nodemon globally?

a)

npm install nodemon -g

b)

npm install --global nodemon

c)

npm install nodemon

d)

npm install -g nodemon

19.

How can you send a JSON response in Express?

a)

Use res.write({ key: 'value' });

b)

Use res.send({ key: 'value' });

c)

Use res.json({ key: 'value' });

d)

Use res.sendFile({ key: 'value' });

20.

What is the significance of the 'db.json' file in a Node.js application?

a)

The 'db.json' file is used for logging application errors.

b)

The 'db.json' file is significant as it acts as a mock database for storing application data in JSON format.

c)

The 'db.json' file serves as a configuration file for server settings.

d)

The 'db.json' file is a template for generating HTML pages.