Express Flashcards

1
Q

How do you add express to your package dependencies?

A

npm install express

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

The app.listen() method is used to bind and listen the connections on the specified host and port. This method is identical to Node’s http.Server.listen() method.

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

What is a network interface?

A

A piece of hardware on a computer that allows net work connectivity (internet).
Examples:
- Each network interface is given it’s own IP address on your network.
- wifi card / adapter, LAN card or adapter
- LAN: Local Area Network (ethernet cable)
- Your phone and laptop have wifi cards
- Your laptop may have LAN
- Every network interface provides 2^16 “ports”.
- The default (aka “well-known”) HTTP port is actually 80 and 443 for HTTPS.
- Anything port number below 1024 require “admin privileges to use”.

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

Why is the difference between a library and a framework?

A
  • A library is code that someone else wrote (or a separate part of your code base)
  • A library should be reusable (flexible) Ex. Lodash
  • A framework is a specific kind of library
  • A framework is different from a library when it has “inversion of control” <== who calls who? (The Hollywood principle)
  • A framework calls YOUR code
  • A library is called by your code
  • A framework decides WHEN to call your functions (you don’t call them) <== ex. event listeners (you define the DOM and you hand it over to the event lister and THEY decide when your function is called).
  • Anything that uses events is a framework
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you mount a middleware with an Express application?

A

use() method

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

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

A

The request object (req) and the response object (res)

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

What is req and res?

A

req: a data model of the HTTP request message (FROM the client!)
res: a data model of the HTTP response (TO the client!)

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

What is middleware?

A

a function that takes in req and res
All requests end with something being sent (res.send() or res.json()) to the client.

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

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

A

Content-Type: application/json; charset=utf-8

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

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

A

json() is a built-in middleware function in Express. This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser. This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option.

Express.json only parses the request.

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

What do HTTP response status codes mean?

A
  1. Informational responses (100–199)
  2. Successful responses (200–299)
  3. Redirection messages (300–399)
  4. Client error responses (400–499)
  5. Server error responses (500–599)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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.

example:
GET
The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.

HEAD
The HEAD method asks for a response identical to a GET request, but without the response body.

POST
The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.

PUT
The PUT method replaces all current representations of the target resource with the request payload.

DELETE
The DELETE method deletes the specified resource.

CONNECT
The CONNECT method establishes a tunnel to the server identified by the target resource.

OPTIONS
The OPTIONS method describes the communication options for the target resource.

TRACE
The TRACE method performs a message loop-back test along the path to the target resource.

PATCH
The PATCH method applies partial modifications to a resource.

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

Number() vs parseInt()

A

Number only changes the data type of numbers, it does not tolerate non-digit.
parseInt will convert all the numbers it sees first in a string that include a digit.

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

What does express.static() return?

A

A middleware function

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

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

A

__dirname is an environment variable that tells you the absolute path of the directory containing the currently executing file.

The absolute path of the directory name of the current module. This is the same as the path.dirname() of the __filename.

absolute path starts at the root of the file folder

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

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

A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

gives any number of arguments and combines them together.

17
Q

How do you make your own API?

A

app.get(‘/api/donkey’, (req, res) => {
res.json({
eddie: murphy
})
})