Description
Over 60 high-quality recipes covering debugging, security, performance, microservices, web frameworks, databases, deployment and more; rewritten for Node 4, 6, and 8.
About This Book
• Security between Node.js and browser applications explained and applied in depth
• Cutting edge techniques and tools for measuring and improving performance
• Contemporary techniques to create developer-ergonomic, readily-scalable production systems
Who This Book Is For
If you have good knowledge of JavaScript and want to build fast, efficient, scalable client-server solutions, then this book is for you. Some experience with Node.js is assumed to get the most out of this book. If working from a beginner level Node Cookbook 2nd Edition is recommended as a primer for Node Cookbook 3rd Edition.
What You Will Learn
• Rapidly become proficient at debugging Node.js programs
• Write and publish your own Node.js modules
• Become deeply acquainted with Node.js core API's
• Use web frameworks such as Express, Hapi and Koa for accelerated web application development
• Apply Node.js streams for low-footprint infinite-capacity data processing
• Fast-track performance knowledge and optimization abilities
• Compare and contrast various persistence strategies, including database integrations with MongoDB, MySQL/MariaDB, Postgres, Redis, and LevelDB
• Grasp and apply critically essential security concepts
• Understand how to use Node with best-of-breed deployment technologies: Docker, Kubernetes and AWS
Chapter
Chapter 1: Debugging Processes
Debugging Node with Chrome Devtools
Using node-inspector with older node versions
Immediately pausing a process on start
Enhancing stack trace output
Infinite stack trace limit in development
Asynchronous stack traces
Instrumenting code with debug
Using debug in production
JSON logging with pino-debug
Creating our own NODE_DEBUG flags
Debugging Node core libraries
Chapter 2: Writing Modules
Installing development dependencies
Eliminating the need for sudo
Detecting Vulnerabilities
Using a private repository
Chapter 3: Coordinating I/O
Interfacing with standard I/O
Asynchronous file operations
Getting symlink information
Watching files and directories
Watching directories with chokidar
Communicating over sockets
Processing infinite amounts of data
Flow mode versus pull-based streaming
Understanding stream events
Keeping piped streams alive
Piping streams in production
Use pumpify to expose pipelines
Creating transform streams
Transform streams with Node's core stream module
Creating object mode transform streams
Creating readable and writable streams
Readable and writable streams with Node's core stream module
Core readable streams flow control issue
Chapter 5: Wielding Web Protocols
Binding to a random free port
Processing all field types in multipart data
Making an HTTP POST request
Communicating with WebSockets
Creating a Node.js WebSocket client
Chapter 6: Persisting to Databases
Connecting and sending SQL to a MySQL server
Querying a MySQL database
Connecting and sending SQL to a Postgres server
Storing object-modelled data
Storing and retrieving data with MongoDB
Updating modifiers, sort, and limit
Storing and retrieving data with Redis
Embedded persistence with LevelDB
Alternative storage adapters
Chapter 7: Working with Web Frameworks
Creating an express web app
Route parameters and POST requests
Performing asynchronous lookups
Adding a view layer to Koa
Adding a view layer to Hapi
ES2015 template strings as views
Pino transports and prettifying
Capturing debug logs with with Pino
Implementing authentication
Session authentication in Hapi
Session authentication in Koa
Chapter 8: Dealing with Security
Detecting dependency vulnerabilities
Restricting core module usage
Hardening headers in web frameworks
Hardening a core HTTP server
Anticipating malicious input
Dealing with JSON pollution
Guarding against cross site scripting (XSS)
Preventing protocol-handler-based XSS
Escaping in JavaScript contexts
Preventing cross site request forgery
Chapter 9: Optimizing Performance
Measuring POST performance
Finding bottlenecks with flamegraphs
CPU profiling with Chrome Devtools
Optimizing a synchronous function call
Checking the optimization status
Tracing optimization and deoptimization events
Optimizing asynchronous callbacks
Visualizing memory usage in the Terminal
Chapter 10: Building Microservice Systems
Creating a simple RESTful microservice
Using the core HTTP module
Testing microservices with a browser
Setting up a development environment
A minimal alternative to fuge
Standardizing service boilerplate
Using containerized infrastructure
Running containers in the background
Service discovery with DNS
Alternative service discovery mechanisms
Viewing the environment and DNS Zone
Adding a Queue Based Service
Entering a containers shell environment
Chapter 11: Deploying Node.js
Building a container for a Node.js process
Viewing the layers in a Docker image
Running a Docker registry
Storing images on DockerHub
Using a specific version tag
Deploying a container to Kubernetes
Using the minikube dashboard
Pushing microservice updates into Kubernetes
Creating a deployment pipeline
Automating the build trigger
Inspecting the kops State Store