Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorEthan Brown

Build dynamic web applications with Express, a key component of the Node/JavaScript development stack. In this updated edition, author Ethan Brown teaches you Express fundamentals by walking you through the development of an example application. This hands-on guide covers everything from server-side rendering to API development suitable for usein single-page apps (SPAs). Express strikes a balance between a robust framework and no framework at all, allowing you a free hand in your architecture choices. Frontend and backend engineers familiar with JavaScript will also learn best practices for building multipage and hybrid web apps with Express. Pick up this book anddiscover new ways to look at web development. Create a templating system for rendering dynamic data Dive into request and response objects, middleware, and URL routing Simulate a production environment for testing Persist data in document databases with MongoDB and relational databases with PostgreSQL Make your resources available to other programs with APIs Build secure apps with authentication, authorization, and HTTPS Integrate with social media, geolocation, and more Implement a plan for launching and maintaining your app Learn critical debugging skills

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, project-driven guide for JavaScript developers who want to build full-stack web applications with Node and Express, covering everything from basic routing to SPAs, databases, and production deployment. 【Book Arc】 - **Opening (~0%–10%)**: Introduces the Node/Express stack and the core distinction between server-side rendered (SSR) apps and single-page applications (SPAs). Sets up the development environment, including shell choices for Windows and Unix users, and explains the philosophy of Express as a "balanced" framework that gives you architectural freedom. - **Early (~10%–23%)**: Builds the foundation with the Meadowlark Travel example app. Covers basic routing with `app.get`, serving static resources, and creating dynamic views with templating. Introduces testing early, showing how to use Jest to unit-test route handlers and Puppeteer for browser-level tests. - **Early-to-Middle (~23%–39%)**: Dives deep into Express fundamentals: request and response objects, middleware patterns, and URL routing. Explains the response methods (`res.send`, `res.json`, `res.format`, etc.) and transitions into templating with Handlebars, including custom helpers and layout sections for injecting head/script content. - **Middle (~39%–48%)**: Moves into real-world application features: form handling with file uploads (multipart/form-data), externalizing credentials via environment-specific config files, and implementing flash messages with session middleware. Emphasizes security practices like CSRF tokens and keeping secrets out of version control. - **Late (~48%–end)**: Covers advanced topics: sending HTML email with Nodemailer (including the quirks of email HTML), building APIs for programmatic access, and creating single-page applications with React. Finishes with static content performance, CDN design, caching strategies, and a launch/maintenance plan. 【Key Takeaways】 - **Express is a "balanced" framework** (Early): It sits between a full-featured framework and no framework at all, giving you architectural freedom. This means you choose your own templating engine, database, and structure—but also means you must make those choices deliberately. - **Middleware order matters** (Early): Express processes middleware in declaration order, and static middleware declared early can override your routes. If you get confusing results, check your static files for unexpected matches—a common debugging gotcha. - **Testing route handlers is simpler than you think** (Early): You don't need to simulate full request/response objects. With Jest, use empty objects for `req` and mock only the `res.render` method with `jest.fn()` to assert what your handlers do. - **Templating is still relevant** (Early): While frontend frameworks dominate, server-side templating with Handlebars remains useful for HTML email and transfers conceptually to Angular/Vue templates. Handlebars comments (`{{! }}`) are stripped server-side, unlike HTML comments—use them for secrets. - **Externalize credentials by environment** (Middle): Store secrets like cookie secrets and API tokens in environment-specific files (e.g., `.credentials.development.json`) and load them via a config module. Add `.credentials.*` to `.gitignore` to avoid leaking secrets in public repos. - **Flash messages need careful middleware** (Middle): To show a message once, transfer it from the session to `res.locals` with middleware, then delete it from the session immediately. This prevents stale messages from appearing on subsequent requests. - **HTML email is a different beast** (Late): Email clients support only a subset of HTML—think tables for layout, circa 1996. Always provide both text and HTML versions, and use Nodemailer to auto-generate plain text from HTML if needed. 【Reading Tips】 - **Skim the environment setup** (~0%–10%) if you're already comfortable with Node and command-line tools; jump straight to the routing examples in Chapter 3. - **Deep-read the middleware and routing chapters** (~23%–39%): These are the heart of Express. Pay special attention to the order of middleware and the differences between `res.send`, `res.json`, and `res.end`. - **Follow the Meadowlark Travel example closely**—it's the thread that ties all concepts together. When you hit the credentials/config section (~42%), implement it even if you're just experimenting; it's a best practice you'll reuse. - **Don't skip the testing chapter** (~19%–23%): The Jest patterns shown here are minimal but transferable to any Express project, and they'll save you hours of manual debugging later. - **Skim the SPA chapter** (~end) if you're already familiar with React; the key takeaway is how Express serves as an API backend for client-side apps, not the React basics themselves. 【Coverage Limits】 This guide synthesizes the first ~48% of the book in detail (setup, routing, middleware, templating, forms, and security). The later chapters on APIs, SPAs, and static content/CDN are covered at a high level from the table of contents and brief excerpts; the excerpts do not cover the book's final chapters on deployment, maintenance, or debugging in depth.
Excerpt 1
cations d. Caching Static Assets Preface How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc....
View in text
Excerpt 2
tunes = [ "Conquer your fears or they will conquer you.", "Rivers need springs.", "Do not fear what you don't know.", "You will have a pleasant surprise.", "...
View in text
Excerpt 3
HTML email. Also, Angular and Vue both use a template-like approach to writing HTML, so what you learn about server-side templating will transfer to those fr...
View in text
Excerpt 4
hey sign up. This is what our form handler might look like: // slightly modified version of the official W3C HTML5 email regex: // https://html.spec.whatwg.o...
View in text
Excerpt 5
orage mechanism buckets, while Azure calls them containers). It’s beyond the scope of this book to detail all of that information, and it is well-documented:...
View in text
Excerpt 6
have to go out of your way to establish state, for example. So our work is mostly cut out for us. JSON and XML Vital to providing an API is having a common l...
View in text
Excerpt 7
port whole multiple domains so, for example, you could have meadowlarktravel.com, meadowlarktravel.us, meadowlarktravel.com, and the www variants. Domain, or...
View in text
Excerpt 8
er app doesn’t do anything (in the traditional sense). It’s more like a set of credentials that you can use to create the actual app on Now we have a nice so...
View in text
Tags
AI categories
BackendJavaScriptWeb Technology
ISBN: 1492053511
Publisher: O'Reilly Media
Publish Year: 2019
Language: English
Pages: 346
File Format: PDF
File Size: 3.5 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…