w3 Flashcards

1
Q

What is Express?

A

Express is a web application framework for Node.js.

provides all of the tools and basic building blocks you need to get a web server up and running by writing very little code.

allowing us to focus on the application’s logic and content.

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

In express what do we not have to do that in node.js we do?

A

we don’t need to-

specify the response headers 200,400 or

add a new line at the end of the string because the framework does it for us.

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

URL routing

app.get(‘/ab?cd’, function (req, res) {
res.send(‘ab?cd’)
})

A

This route path will match acd and abcd.

b is silent

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

app.get(‘/ab+cd’, function (req, res) {
res.send(‘ab+cd’)
})

A

This route path will match abcd, abbcd, abbbcd, and so on

b can be any number of letters

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

app.get(‘/abcd’, function (req, res) {
res.send(‘ab
cd’)
})

A

This route path will match abcd, abxcd, abRANDOMcd, ab123cd, and so on.

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

app.get(‘/ab(cd)?e’, function (req, res) {
res.send(‘ab(cd)?e’)
})

A

This route path will match /abe and /abcde.

cd is silent

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

app.get(/a/, function (req, res) {
res.send(‘/a/’)
})

A

This route path will match anything with an “a” in it.

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

app.get(/.fly$/, function (req, res) {
res.send(‘/.
fly$/’)
})

A

This route path will match butterfly and dragonfly, but not butterflyman, dragonflyman, and so on.

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

Router parameters

A

Route parameters are named URL segments that are used to capture the values specified at their position in the URL. The captured values are populated in the req.params object, with the name of the route parameter specified in the path as their respective keys.

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

Query string

A

To get the list of query string parameters in a route, req.query can be used

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

Router parameters vs query string

A

Router parameters- req.param object

Query string- req.query

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

Router-level middleware use?

A

For the sake of separation of concerns (SoC) and maintainability,

t is possible to separate the routes from the main js file using Express.Router

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

In order to accept requests with a path that starts with BI, ends with DX, and zero or more characters in between, we have to use:

A

app.get(‘/BI*DX, function(res,res){

});

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

Assume you have this fragment of code

app.get(‘/item’, function (req, res) {
// print out the item id
})

and the client sends this request:

http://localhost:8080/item?id=123

Which statement prints the value of the id to the console?

A

console.log(req.query.id)

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

Assume you have this fragment of code:

app.get(‘/item(w2)?warehouse’, function(req, res){
res.send(‘We got a match’);
})

This route path will match:

A

/itemwarehouse and /itemw2warehouse

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

Assume you have this fragment of code:

app.get(‘/items/:itemid’, function (req, res) {
//do something
})

The data type of req.params is:

A

object