Node – req, res, app

Przydatne metody

Usuwa domyślny nagłówek http o serwerze

 app.disable('x-powered-by')

Request

req.params      - named route params
req.query       - ?search=string
req.body      
  
req.cookies 
req.session 
req.headers

req.accepts(mime-type) - string lub array
req.ip
req.path
req.hostname
req.xhr                - czy pochodzi z AJAX
req.protocol           - http, https
req.secure             - req.protocol === 'https'
req.url  / .originalUrl

Response

res.status              - 200 default
res.set(name, value)    - ustawienie nagłówka http

res.cookie(name, value, [options])  
res.clearCookie(name, [options])

res.redirect([status,] url)     - 302 default
res.send(body)                  - szybka odp. / def. text/html
res.json(json)
res.jsonp(json)
res.type(type)       
           
res.format(object)              - body zależne od typu
res.format({
  'text/plane'       : 'Hello', 
  'text/html'        : '<h1>Hello</h1>',
  'application/xml'  : () => res.redirect(303, '/xml_content'),
  'application/json' : () => res.json({success : 1}),
  'image/jpeg'       : () => res.status(500).type('text/plane').send('Error - Not allowed'})
})

res.attachment([filename])      - ust. nagłówek Content-Disposition: Attachment, + ew. nazwę pliku 
res.download(path, [filename,] [callback])  - ustawia plik do wysłania
res.sendFile(path, [options], [callback]) - wysyła plik do klienta

res.links(links)                - nagłówek Links

res.locals           - kontekst do wykonania renderowania

res.render(view, [locals], [callback])