w4 Flashcards

1
Q

Express.js app.set

A

to define a value based on key and value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Express.js app.get

A

app.get to retrieve the value based on the key/name of the setting.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Third-party middleware

A

invoked by express for tasks- has access to response and request objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Morgan

A

HTTP request logger middleware for node.js.

It generates logs automatically for any request being made.

It has a set of predefined formats such as tiny, short, common, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

can intercept request and do pre-processing through middleware by?

A

app.use()

app.use(function (req, res, next) {
req.timestamp = new Date().toISOString();
next();
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

purpose of next function in middleware preprocessing

A

The next() function represents the next middleware function to be executed. If you choose not to call function next(), the request will be left hanging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Parsing app for POST method

A

// parse application/x-www-form-urlencoded
app.use(express.urlencoded({extended: true}));
// parse application/json
app.use(express.json())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

req.body

A

Extracting for post requests using body-parser middleware

app.post(‘/data’, function (req, res) {
console.log(req.body.username);
console.log(req.body.userage);
res.send(‘Thank You’)

})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

GET vs POST requests

A

GET request is used to get data from the server, such as HTML files. Express.js handles GET requests by using app.get (lines 9-11).

POST request is used to send data from the client to the server such as username and password fields. Express.js handles POST requests by using app.post (lines 12-17)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Rendering engine

A

Use static files in app
Runtime-> engine will replace template values with actual values and transform to HTML file
design dynamic HTML files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Most popular view engine

A

EJS (Embedded JS)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

EJS?

A

EJS is a simple templating language that lets you generate HTML markup with plain JavaScript.

No religiousness about how to organize things.

No reinvention of iteration and control-flow. It’s just plain JavaScript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

EJS engine config

A

app.engine(‘html’, require(‘ejs’).renderFile);
app.set(‘view engine’, ‘html’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

res.render() ?

A

method each time you need to send an HTML file to a client.

renders a view and sends the rendered HTML string to the client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

res.render() optional parameters

A

locals, an object whose properties define local variables for the view.

callback, a callback function. If provided, the method returns both the possible error and rendered string but does not perform an automated response. When an error occurs, the method invokes next(err) internally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

<%= %>

A

we have to use <%= %> tags to print out the attribute’s value. for EJS rendering

17
Q

app.use(express.static(‘public’))

A

Serving static files i.e images, CSS files, and JavaScript files in a directory named public

18
Q

To have a global variable that can be used in any template in Express.js, I have to:

A

app.set() and provide a pair of key and value

19
Q

To serve static files such as images, CSS files, and JavaScript files?

A

use the express.static built-in middleware function in Express.

20
Q

default loc of HTML files for EJS view engine

A

[root]/views

21
Q

Form method and action attribute?

A

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute).

The action attribute specifies where to send the form-data when a form is submitted.
absolute URL or relative URL