Show Menu

Express.js Cheat Sheet by

Quick list of the stuff you're most likely to need when using express.js without coffee(PUN!)
javascript     web     node-js     express     express-js

Settings

app.set('x', 'yyy')
app.get('x') //=> 'yyy'

app.enable('trust proxy')
app.disable('trust proxy')

app.enabled('trust proxy') //=> true

Request

// GET /user/tj
req.path //=> "/user/tj"
req.url //=> "/user/tj"
req.xhr //=> true|false
req.method //=> "GET"
req.params
req.params.name //=> "tj"
req.params[0]

// GET /search?q=tobi+ferret
req.query.q // => "tobi ferret"

req.cookies

req.accepted
[ { value: 'application/json', quality: 1, type: 'application', subtype: 'json' },
  { value: 'text/html', quality: 0.5, type: 'text',subtype: 'html' } ]

req.is('html')
req.is('text/html')

req.headers
req.headers['host']
req.headers['user-agent']
req.headers['accept-encoding']
req.headers['accept-language']

Response

res.redirect('/')
res.redirect(301, '/')

res.set('Content-Type', 'text/html')

res.send('hi')
res.send(200, 'hi')

res.json({ a: 2 })
 

Env

app.get('env')

Config

app.configure('production', function() {
  app.set...
});

Wares

app.use(express.static(__dirname + '/public'));
app.use(express.logger());

Helpers

app.locals({
  title: "MyApp",
});

Download the Express.js Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/tofagerl_express-js.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          JavaScript Cheat Sheet
          Web Programming Cheat Sheet
          SailsJS Cheat Sheet