万本电子书0元读

万本电子书0元读

顶部广告

Mastering Web Application Development with Express电子书

售       价:¥

1人正在读 | 0人评论 9.8

作       者:Alexandru Vl?du?u

出  版  社:Packt Publishing

出版时间:2014-09-25

字       数:207.9万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
If you are a Node.js developer who wants to take your Express skills to the next level and develop high performing, reliable web applications using best practices, this book is ideal for you. The only prerequisite is knowledge of Node.js.
目录展开

Mastering Web Application Development with Express

Table of Contents

Mastering Web Application Development with Express

Credits

About the Author

About the Reviewers

www.PacktPub.com

Support files, eBooks, discount offers, and more

Why subscribe?

Free access for Packt account holders

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

Questions

1. Diving into Express

The best parts of Express

Comparing Express with other frameworks

Goal

Conventions

Databases

Views

Overall

Use cases

Complex applications with heavy I/O bound operations

Single-page applications

Reusable applications

Code sharing between the server and the client

A base to create more complex frameworks

Bad use cases

Express into the wild

The application structure

Group files by features

Model-View-Controller

Developing a real MVC application

Bootstrapping a folder structure

Installing NPM dependencies

Setting up the configuration file

The starting script

The database library

Routes

Models

The file model

The User model

Views

Running the full application

Summary

2. Component Modularity Using Middleware

Connecting middleware

The functionality of middleware

Pushing items to an array

Looking at the execution flow using logs

Creating configurable middleware

Closures to the rescue

Caching middleware – a practical example

A first try at the caching middleware

Measuring the performance benefits of the caching middleware

Making the caching middleware configurable

Environment-based loading of middleware

Express routes

Specifying the path

Reusable route handlers

Route wildcards

Ordering of middleware

Handling errors with middleware

Mounting subapplications

Replicating the middleware system

The main file

Handling requests

Demonstrating the application

Adding the routes handler

Summary

3. Creating RESTful APIs

An overview of REST

HTTP methods (verbs)

HTTP status codes

Successful 2xx

Redirection 3xx

Client error 4xx

Server error 5xx

SmartNotes application requirements

Creating RESTful URLs of the application

Implementing the SmartNotes application

The bootstrapping phase

Dealing with validation

Creating a custom validation module

Improving performance with memoization

Implementing the models

Test helpers

The Note model

The User model

Functional tests and route implementation

User endpoints

Notes endpoints

API versioning

API rate limiting

Throttling

Facilitating caching

Content negotiation

Summary

4. Leveraging the Power of Template Engines

The different types of template engines

Logic-less template engines

Template engines with logic

Programmatic template engines

View helpers and application-level data

Sharing code between templates with partial views

DRY templates with layouts

Template engine consolidation with consolidate.js

View caching in production

The view cache setting and its effect

Clearing the cache without a restart

Integrating a template engine with Express

Choosing a template engine

Summary

5. Reusable Patterns for a DRY Code Base

Creating the MovieApp sample application

Application structure and required modules

Creating the server.js file

Creating the route handlers

Doing the heavy lifting inside the model

Wrapping it up

Error checks and callback functions

Tiny modules for better control flow

Ensuring a single callback execution

Extending objects in a reusable way

A simple way to create custom errors

Summary

6. Error Handling

Runtime (operational) errors and human errors

Ways of delivering errors in the Node applications

Throwing errors in the synchronous style

The error-first callback pattern

The EventEmitter errors

Strings instead of errors as an antipattern

Improving stack traces

Handling uncaught exceptions

Logging errors

Creating a custom Express error handler

Richer errors with VError

Error handling in a practical application

Creating the application entry point

Real-time updates with Primus

Post and User models

About routes

Views and static resources

Running the application

Summary

7. Improving the Application's Performance

Serving static resources with Express

Using Node modules

The middleware order can impact performance

Asset versioning

Compress and minify

An in-memory static middleware

Using a content delivery network

Using NGiNX

Backend improvements

Avoiding synchronous functions

Doing things in parallel whenever possible

Using streams to process data

Streaming templates with trumpet

Caching dynamic data

ETag for dynamic data

Using a cluster to handle more concurrent connections

HTTPS with Stud

Summary

8. Monitoring Live Applications

Logging

Bunyan – a battle-tested logger

Redirecting logs to an external service

Things to note

Simple tips for improving the application monitoring

Collecting metrics

Getting the slowest endpoints of the application

Tracking the network traffic

Measuring the average function response time

Useful existing monitoring tools

Ensuring the application uptime

Summary

9. Debugging

A better error-handling middleware

Application for displaying the time in the current time zone

Adding the improved error handler

Using a debug flag

Debug versus logger

Debugging routes and middleware

Using the V8 debugger

Creating our buggy application

Using Node's debugger client in the terminal

Using node-inspector

Debugging memory leaks

Adding a REPL to our Express application

Removing debugging commands

Summary

10. Application Security

Running Express applications on privileged ports

Dropping root privileges

Redirecting to another port using iptables

Using authbind

Cross-site request forgery protection

Cross-site scripting

Validating input

Sanitizing output

HTTP security headers with Helmet

Handling file uploads

Session middleware parameters

Reauthenticating the user for sensitive operations

Summary

11. Testing and Improving Code Quality

The importance of having automated tests

Testing toolbox

Mocha

should.js

Sinon.js

Spies

Stubs

Mocks

Supertest

Proxyquire

Generating phony data using Faker.js

Creating and testing an Express file-sharing application

Running the application

Unit tests

Functional tests

Running tests before committing in Git

Code coverage

Complexity analysis of our code

Code linting

Load testing

Client-side testing

Continuous Integration

CI servers

Free CI for open source projects

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部