Pro Express.js

Book description

Pro Express.js is for the reader who wants to quickly get up-to-speed with Express.js, the flexible Node.js framework. Author Azat Mardan clearly explains how to start developing with Express.js with a basic 'Hello World', and then delves into a deep API reference, before looking at common and abstract development problems. Lastly, you will learn how to build a series of real-world apps in order to cement your knowledge.

In order to get the best from this book, you will be familiar with Node.js scripts and able to install packages using npm. In the deep API reference, each aspect of the Express.js API is explained clearly with a simple exercise to demonstrate its usage. This includes configuration, settings and environments; different middleware and its uses; templating engines; extracting parameters and routing; request and response; error handling; and running an app. In the next part you'll delve into abstraction, streams, authentication, multithreading, Socket.io, security, and more complex modules. You will also learn about smaller frameworks built using Express.js, such as Sails.js, and Derby. Finally you'll build real-world apps including a REST API, Todo App, and Instagram gallery.

Express.js is used by a range of well-known companies such as MySpace and Storify, and it's becoming more and more likely that it'll be a required skill for new developers. With this book you can skip learning via complicated documentation, and get the information from a developer who's been using Express.js for long enough to explain things well. Add Pro Express.js to your library today.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Author
  7. About the Technical Reviewers
  8. Foreword
  9. Acknowledgments
  10. Introduction
  11. Part I: Getting Started
    1. Chapter 1: Starting with Express.js
      1. How Express.js Works
        1. Third-Party Dependencies
        2. Instantiations
        3. Connecting to Databases
        4. Configuring Express.js App Settings
        5. Defining Middleware
        6. Defining Routes
        7. Starting the App
      2. Express.js Installation
      3. Express.js Generator Installation
      4. Summary
    2. Chapter 2: Hello World Example
      1. Getting Started
        1. Using Request Handlers
        2. Outputting Terminal Messages
        3. Enhancing the App
      2. Generator Commands
        1. Generating a Skeleton Express.js app
        2. Reviewing the Application’s Structure
      3. MVC Structure and Modules
      4. Watching for File Changes
      5. Summary
  12. Part II: Deep API Reference
    1. Chapter 3: Configuration, Settings, and Environments
      1. Configuration
        1. app.set() and app.get()
        2. app.enable() and app.disable()
        3. app.enabled() and app.disabled()
      2. Settings
        1. env
        2. view cache
        3. view engine
        4. views
        5. trust proxy
        6. jsonp callback name
        7. json replacer and json spaces
        8. case sensitive routing
        9. strict routing
        10. x-powered-by
        11. etag
        12. query parser
        13. subdomain offset
      3. Environments
      4. Summary
    2. Chapter 4: Working with Middleware
      1. Applying Middleware
      2. Essential Middleware
        1. compression
        2. morgan
        3. body-parser
        4. urlencoded()
        5. cookie-parser
        6. express-session
        7. csurf
        8. express.static()
        9. connect-timeout
        10. errorhandler
        11. method-override
        12. response-time
        13. serve-favicon
        14. serve-index
        15. vhost
        16. connect-busboy
      3. Other Middleware
      4. Summary
    3. Chapter 5: Template Engines and Consolidate.js
      1. How to Use Template Engines
        1. app.engine()
        2. Uncommon Libraries
      2. Template Engine Choices
        1. Jade
        2. Haml.js
        3. EJS
        4. Handlebars.js
        5. Hogan.js Adapters
        6. Combyne.js
        7. Swig
        8. Whiskers
        9. Blade
        10. Haml-Coffee
        11. Webfiller
      3. Consolidate.js
      4. Summary
    4. Chapter 6: Parameters and Routing
      1. Parameters
        1. app.param()
      2. Routing
        1. app.VERB()
        2. app.all()
        3. Trailing Slashes
        4. Router Class
        5. router.route(path)
      3. Request Handlers
      4. Summary
    5. Chapter 7: Express.js Request Object
      1. request.query
      2. request.params
      3. request.body
      4. request.route
      5. request.cookies
      6. request.signedCookies
      7. request.header() and request.get()
      8. Other Attributes and Methods
      9. Summary
    6. Chapter 8: Express.js Response Object
      1. response.render()
      2. response.locals
      3. response.set()
      4. response.status()
      5. response.send()
      6. response.json()
      7. response.jsonp()
      8. response.redirect()
      9. Other Response Methods and Properties
      10. Streams
      11. Summary
    7. Chapter 9: Error Handling and Running an App
      1. Error Handling
      2. Running an App
        1. app.locals
        2. app.render()
        3. app.mountpath
        4. app.on(‘mount’, function(parent){...})
        5. app.path()
        6. app.listen()
      3. Summary
  13. Part III: Solving Common and Abstract Problems
    1. Chapter 10: Abstraction
      1. Middleware
      2. Routes
      3. Combining Middleware and Routes
      4. Summary
    2. Chapter 11: Database, Keys and Stream Tips
      1. Using Databases in Modules
      2. Keys and Passwords
        1. JSON File
        2. Environment Variables
      3. Streams
      4. Summary
    3. Chapter 12: Redis and Authentication Patterns
      1. Redis
      2. Authentication Patterns
      3. Summary
    4. Chapter 13: Multithreading with Clusters
      1. A Multithreading Example
      2. Summary
    5. Chapter 14: Applying Stylus, Less, and Sass
      1. Stylus
      2. Less
      3. Sass
      4. Summary
    6. Chapter 15: Security Tips
      1. Cross-Site Request Forgery
      2. Process Permissions
      3. HTTP Security Headers
      4. Input Validation
      5. Summary
    7. Chapter 16: Socket.IO and Express.js
      1. Using Socket.IO
      2. Running the App
      3. Summary
    8. Chapter 17: Domain and Express.js
      1. Defining the Problem
      2. Exploring a Basic Domain Example
      3. Writing a Domain App
      4. Summary
    9. Chapter 18: Sails.js, DerbyJS, LoopBack, and Other Frameworks
      1. Sails.js
      2. DerbyJS
      3. LoopBack
      4. Other Frameworks
      5. Summary
  14. Part IV: Tutorials and Examples
    1. Chapter 19: Instagram Gallery
      1. Starting the Instagram Gallery
      2. Viewing the Gallery
      3. Summary
    2. Chapter 20: Todo App
      1. Overview
      2. Setup
      3. App.js
      4. Routes
      5. Jade
      6. Less
      7. Summary
    3. Chapter 21: REST API
      1. RESTful API Basics
      2. Test Coverage
      3. Dependencies
      4. Server Implementation
      5. Summary
    4. Chapter 22: HackHall
      1. What Is HackHall?
      2. Running HackHall
      3. Structure
      4. Package.json
      5. Express.js App
      6. Routes
        1. index.js
        2. auth.js
        3. main.js
        4. users.js
        5. application.js
        6. posts.js
      7. Mongoose Models
      8. Mocha Tests
      9. Summary
    5. Appendix A: Related Reading and Resources
      1. Other Node.js Frameworks
      2. Node.js Books
      3. JavaScript Classics
      4. Courses
    6. Appendix B: Migrating Express.js 3.x to 4.x: Middleware, Route, and Other Changes
      1. Introducing Unbundled Middleware in Express.js 4
      2. Removing Deprecated Methods from Express.js 4 Apps
        1. app.configure()
        2. app.router
        3. res.on(‘header’)
        4. res.charset
        5. res.headerSent
        6. req.accepted()
      3. Other Express.js 4 Changes
        1. app.use()
        2. res.location()
        3. app.route()
        4. json spaces
        5. req.params
        6. res.locals
        7. req.is
        8. Express.js Command-Line Generator
      4. Exploring the New Express.js 4 Route Instance and How to Chain It
      5. Further Express.js 4 Migration Reading Links
    7. Appendix C: Express.js 4 Cheat Sheet
      1. Installation
      2. Generator
      3. Basics
      4. HTTP Verbs and Routes
      5. Request
      6. Request Header Shortcuts
      7. Response
      8. Handlers Signatures
      9. Stylus and Jade
      10. Body
      11. Static
      12. Connect Middleware
      13. Other Popular Middleware
    8. Appendix D: ExpressWorks
      1. Installation
      2. Usage
      3. Resetting
      4. Tasks
        1. Hello World
        2. Jade
        3. Good Old Form
        4. Static
        5. Stylish CSS
        6. Param Pam Pam
        7. What’s in a Query
        8. JSON Me
      5. Summary
  15. Index

Product information

  • Title: Pro Express.js
  • Author(s):
  • Release date: December 2014
  • Publisher(s): Apress
  • ISBN: 9781484200377