Table of Contents for
React Quickly: Painless web apps with React, JSX, Redux, and GraphQL

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition React Quickly: Painless web apps with React, JSX, Redux, and GraphQL by Azat Mardan Published by Manning Publications, 2017
  1. Cover
  2. React Quickly: Painless web apps with React, JSX, Redux, and GraphQL
  3. Copyright
  4. React Quickly: Painless web apps with React, JSX, Redux, and GraphQL
  5. Brief Table of Contents
  6. Table of Contents
  7. Praise for React Quickly
  8. Foreword
  9. Preface
  10. Acknowledgments
  11. About This Book
  12. About the Author
  13. About the Cover
  14. Part 1. React foundation
  15. Chapter 1. Meeting React
  16. Chapter 2. Baby steps with React
  17. Chapter 3. Introduction to JSX
  18. Chapter 4. Making React interactive with states
  19. Chapter 5. React component lifecycle events
  20. Chapter 6. Handling events in React
  21. Chapter 7. Working with forms in React
  22. Chapter 8. Scaling React components
  23. Chapter 9. Project: Menu component
  24. Chapter 10. Project: Tooltip component
  25. Chapter 11. Project: Timer component
  26. Part 2. React architecture
  27. Chapter 12. The Webpack build tool
  28. Chapter 13. React routing
  29. Chapter 14. Working with data using Redux
  30. Chapter 15. Working with data using GraphQL
  31. Chapter 16. Unit testing React with Jest
  32. Chapter 17. React on Node and Universal JavaScript
  33. Chapter 18. Project: Building a bookstore with React Router
  34. Chapter 19. Project: Checking passwords with Jest
  35. Chapter 20. Project: Implementing autocomplete with Jest, Express, and MongoDB
  36. Appendix A. Installing applications used in this book
  37. Appendix B. React cheatsheet
  38. Appendix C. Express.js cheatsheet
  39. Appendix D. MongoDB and Mongoose cheatsheet
  40. Appendix E. ES6 for success
  41. React Cheatsheet
  42. Index
  43. List of Figures
  44. List of Tables
  45. List of Listings

Appendix C. Express.js cheatsheet

When you develop your own projects, searching on the internet for React documentation and APIs or going back to this book’s chapters to find a single method isn’t efficient. If you’d like to save time and avoid the distractions lurking everywhere on the Net, use this Express cheatsheet as a quick reference.

Print-ready PDF available

In addition to the text version presented here, I’ve created a free beautifully designed, print-ready PDF version of this cheatsheet. You can request this PDF at http://reactquickly.co/resources.

Installing Express.js

  • $ sudo npm install express—Installs the latest Express.js locally
  • $ sudo npm install express@4.2.0 --save—Installs Express.js v4.2.0 locally, and saves it to package.json
  • $ sudo npm install -g express-generator@4.0.0—Installs the Express.js command-line generator v4.0.0

Generator

Usage

$ express [options] [dir]

Options

  • -h—Prints usage information
  • -V—Prints the express-generator version number
  • -e—Adds EJS engine support; defaults to Jade if omitted
  • -H—Adds hogan.js engine support
  • -c <library>—Adds CSS support for <library> (less|stylus|compass); defaults to plain CSS if -c <library> is omitted
  • -f—Generates into a non-empty directory

Basics

  • var express = require('express')—Includes a module
  • var app = express()—Creates an instance
  • app.listen(portNumber, callback)—Starts the Express.js server
  • http.createServer(app).listen(portNumber, callback)—Starts the Express.js server
  • app.set(key, value)—Sets a property value by key
  • app.get(key)—Gets a property value by key

HTTP verbs and routes

  • app.get(urlPattern, requestHandler[, requestHandler2, ...])—Handles GET method requests
  • app.post(urlPattern, requestHandler[, requestHandler2, ...])—Handles POST method requests
  • app.put(urlPattern, requestHandler[, requestHandler2, ...])—Handles PUT method requests
  • app.delete(urlPattern, requestHandler[, requestHandler2, ...])—Handles DELETE method requests
  • app.all(urlPattern, requestHandler[, requestHandler2, ...])—Handles all method requests
  • app.param([name,] callback)Processes URL parameters
  • app.use([urlPattern,] requestHandler[, requestHandler2, ...])—Applies middleware

Requests

  • request.params—Parameter middleware
  • request.param—Extracts one parameter
  • request.query—Extracts a query string parameter
  • request.route—Returns a route string
  • request.cookies—Accesses cookies; requires cookie-parser
  • request.signedCookies—Accesses signed cookies; requires cookie-parser
  • request.body—Reads a payload; requires body-parser

Request-header shortcuts

  • request.get(headerKey)—Reads Value for the header key
  • request.accepts(type)—Checks whether the type is accepted
  • request.acceptsLanguage(language)—Checks the language
  • request.acceptsCharset(charset)—Checks the character set
  • request.is(type)—Checks the type
  • request.ip—Reads an IP address
  • request.ips—Reads IP addresses (with trust-proxy on)
  • request.path—Reads a URL path
  • request.host—Accesses a host without a port number
  • request.fresh—Checks freshness
  • request.stale—Checks staleness
  • request.xhr—Checks for XHR/AJAX-y requests
  • request.protocol—Returns an HTTP protocol
  • request.secure—Checks whether protocol is https
  • request.subdomains—Reads an array of subdomains
  • request.originalUrl—Reads the original URL

Response

  • response.redirect(status, url)—Redirects a request
  • response.send(status, data)—Sends a response
  • response.json(status, data)—Sends JSON, and forces proper headers
  • response.sendfile(path, options, callback)—Sends a file
  • response.render(templateName, locals, callback)—Renders a template
  • response.locals—Passes data to the template

Handler signatures

  • function(request, response, next) {}Request-handler signature
  • function(error, request, response, next) {}—Error-handler signature

Stylus and Jade

Install Jade and Stylus:

$ npm i -SE stylus jade

Apply the Jade template engine:

app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'jade')

Apply the Stylus CSS processor:

app.use(require('stylus').middleware(path.join(__dirname, 'public')))

Body

var bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
    extended: true
}))

Static

app.use(express.static(path.join(__dirname, 'public')))

Connect middleware

$ sudo npm install <package_name> --save

Other popular middleware

Resources