Express Flashcards

1
Q

How do you add express to your package dependencies?

A

npm install express –save (while you’re in the package directory)

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( )

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

How do you mount a middleware with an Express application?

A

app.use( )

Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.

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

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

A

request and response objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
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
6
Q

app.listen should always be where in the file?

A

It should always be at the end of the file

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

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

A

HTTP defines a set of request methods to indicate the desired action to be performed for a given resource

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

It parses incoming requests with JSON payloads and is based on body-parser.

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.

A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.

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

What does express.static( ) return?

A

Return Value: It returns a function

A middleware function to be specific

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

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

A

__dirname: It is a local variable that returns the directory name of the current module. It returns the folder path of the current JavaScript file. It returns the name the of current working directory. It returns the directory name of the directory containing the source code file.

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

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

A

The path. join( ) method joins the specified path segments into one path. You can specify as many path segments as you like. The specified path segments must be strings, separated by comma.

The path.join( ) method is used to join a number of path-segments using the platform-specific delimiter to form a single path.

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