express Flashcards

1
Q

How do you add express to your package dependencies?

A

npm init –yes –> adds a package.json

npm install express –> adds express as dependency

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

What Express application method starts the server and binds it to a network PORT?

A

app.listen(port#, callback)

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

what is a middleware

A

functions that have access to res and req objects and next. has a call back that can respond to whatever https method call and access the request and response objects to receive the request, do stuff to it and then send a response.

where res and req funnels in, you can use middlewares to mamipulate res and req or to comfirm id data is what you are expecting

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

How do you mount a middleware with an Express application?

A

by adding a url path

app.use(‘/url’, (req, res, next) ==> {})

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

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

request (req) , response (res) objects

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

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json

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

difference between res.send() and res.json()

A

res. send() “guesses which content-type you want to send/revieve”
res. json is json content type fosho

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

What does the express.json() middleware do and when would you need it?

A

parses json package that is being requested and gets places in the req.body

express. json() returns a middleware –> app.use() mounts a middle ware
express. json( app.use( ) )

you would need it whenever dealing with json content types

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

What is the significance of an HTTP request’s method?

A

you can specify an http request method so that a middleware can give an appropriate response from server to client request.

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

What does express.static() return?

A

a middlewear that deals with static files

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

What is the local __dirname variable in a Node.js module?

A

returns the current dirsectory working all the way from the root

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

What does the join() method of Node’s path module do?

A

concatenates directories amd paths

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