express intro Flashcards

1
Q

How do you add express to your package dependencies?

A

By first adding npm init to your project, then installing the package via the command line with the command ‘npm i 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 application method that starts the server and binds it to a network is the listen method ‘.listen()’
Binds and listens for connections on the specified host and port. This method is identical to Node’s http.Server.listen().

If port is omitted or is 0, the operating system will assign an arbitrary unused port, which is useful for cases like automated tasks (tests, etc.).

var express = require('express')
var app = express()
app.listen(3000)

The app returned by express() is in fact a JavaScript Function, designed to be passed to Node’s HTTP servers as a callback to handle requests. This makes it easy to provide both HTTP and HTTPS versions of your app with the same code base, as the app does not inherit from these (it is simply a callback):

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

Commonly used methods and properties for express

A

require()

app. use()
app. send()
app. method()
res. status()
req. originalUrl
res. sendFile()

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

What is the purpose of the Content-Type header in HTTP request and response messages?

A

The Content-Type entity header is used to indicate the media type of the resource. In responses, a Content-Type header tells the client what the content type of the returned content actually is. Browsers will do MIME sniffing in some cases and will not necessarily follow the value of this header; to prevent this behavior, the header X-Content-Type-Options can be set to nosniff.
In requests, (such as POST or PUT), the client tells the server what type of data is actually sent.

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