express Flashcards
How do you add express to your package dependencies?
npm init –yes –> adds a package.json
npm install express –> adds express as dependency
What Express application method starts the server and binds it to a network PORT?
app.listen(port#, callback)
what is a middleware
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 do you mount a middleware with an Express application?
by adding a url path
app.use(‘/url’, (req, res, next) ==> {})
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request (req) , response (res) objects
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
difference between res.send() and res.json()
res. send() “guesses which content-type you want to send/revieve”
res. json is json content type fosho
What does the express.json() middleware do and when would you need it?
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
What is the significance of an HTTP request’s method?
you can specify an http request method so that a middleware can give an appropriate response from server to client request.
What does express.static() return?
a middlewear that deals with static files
What is the local __dirname variable in a Node.js module?
returns the current dirsectory working all the way from the root
What does the join() method of Node’s path module do?
concatenates directories amd paths