DEV Community

Cover image for Express Quick Sheet
Bryan C Guner
Bryan C Guner

Posted on

Express Quick Sheet

Express Quick Sheet

Settings


Express Quick Sheet

Settings

app.set('x', 'yyy')app.get('x') //=> 'yyy'
Enter fullscreen mode Exit fullscreen mode
app.enable('trust proxy')app.disable('trust proxy')
Enter fullscreen mode Exit fullscreen mode
app.enabled('trust proxy') //=> true
Enter fullscreen mode Exit fullscreen mode

Enviorment {#ced4 .graf .graf--h3 .graf-after--pre name="ced4"}

app.get('env')
Enter fullscreen mode Exit fullscreen mode

Config

app.configure('production', function() {  app.set...})
Enter fullscreen mode Exit fullscreen mode

Wares

app.use(express.static(__dirname + '/public'))app.use(express.logger())
Enter fullscreen mode Exit fullscreen mode

Helpers

app.locals({  title: "MyApp",})
Enter fullscreen mode Exit fullscreen mode

Request & response

Request

// GET  /user/tjreq.path         //=> "/user/tj"req.url          //=> "/user/tj"req.xhr          //=> true|falsereq.method       //=> "GET"req.paramsreq.params.name  //=> "tj"req.params[0]
Enter fullscreen mode Exit fullscreen mode
// GET /search?q=tobi+ferretreq.query.q // => "tobi ferret"
Enter fullscreen mode Exit fullscreen mode
req.cookies
Enter fullscreen mode Exit fullscreen mode
req.accepted// [ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' },//   { value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ]
Enter fullscreen mode Exit fullscreen mode
req.is('html')req.is('text/html')
Enter fullscreen mode Exit fullscreen mode

```js {#64c5 .graf .graf--pre .graf-after--pre name="64c5"}
req.headersreq.headers['host']req.headers['user-agent']req.headers['accept-encoding']req.headers['accept-language']




### Response



```js
res.redirect('/')res.redirect(301, '/')
Enter fullscreen mode Exit fullscreen mode
res.set('Content-Type', 'text/html')
Enter fullscreen mode Exit fullscreen mode
res.send('hi')res.send(200, 'hi')
Enter fullscreen mode Exit fullscreen mode
res.json({ a: 2 })
Enter fullscreen mode Exit fullscreen mode

Top comments (0)