Preface

Who This Book Is For

This book is for programmers who want to create web applications (traditional websites; single-page applications with React, Angular, or Vue; REST APIs; or anything in between) using JavaScript, Node, and Express. One of the exciting aspects of Node development is that it has attracted a whole new audience of programmers. The accessibility and flexibility of JavaScript have attracted self-taught programmers from all over the world. At no time in the history of computer science has programming been so accessible. The number and quality of online resources for learning to program (and getting help when you get stuck) is truly astonishing and inspiring. So to those new (possibly self-taught) programmers, I welcome you.

Then, of course, there are the programmers like me, who have been around for a while. Like many programmers of my era, I started off with assembler and BASIC and went through Pascal, C++, Perl, Java, PHP, Ruby, C, C#, and JavaScript. At university, I was exposed to more niche languages such as ML, LISP, and PROLOG. Many of these languages are near and dear to my heart, but in none of these languages do I see so much promise as I do in JavaScript. So I am also writing this book for programmers like myself, who have a lot of experience and perhaps a more philosophical outlook on specific technologies.

No experience with Node is necessary, but you should have some experience with JavaScript. If you’re new to programming, I recommend Codecademy. If you’re an intermediate or experienced programmer, I recommend my own book, Learning JavaScript, 3rd Edition (O’Reilly). The examples in this book can be used with any system that Node works on (which covers Windows, macOS, and Linux, among others). The examples are geared toward command-line (terminal) users, so you should have some familiarity with your system’s terminal.

Most important, this book is for programmers who are excited. Excited about the future of the internet and want to be part of it. Excited about learning new things, new techniques, and new ways of looking at web development. If, dear reader, you are not excited, I hope you will be by the time you reach the end of this book….

Notes on the Second Edition

It was a joy to write the first edition of this book, and I am to this day pleased with the practical advice I was able to put into it and the warm response of my readers. The first edition was published just as Express 4.0 was released from beta, and while Express is still on version 4.x, the middleware and tools that go along with Express have undergone massive changes. Furthermore, JavaScript itself has evolved, and even the way web applications are designed has undergone a tectonic shift (away from pure server-side rendering and toward single-page applications [SPAs]). While many of the principles in the first edition are still useful and valid, the specific techniques and tools are almost completely different. A new edition is overdue. Because of the ascendancy of SPAs, the focus of this second edition has also shifted to place more emphasis on Express as a server for APIs and static assets, and it includes an SPA example.

How This Book Is Organized

Chapter 1 and Chapter 2 will introduce you to Node and Express and some of the tools you’ll be using throughout the book. In Chapter 3 and Chapter 4, you start using Express and build the skeleton of a sample website that will be used as a running example throughout the rest of the book.

Chapter 5 discusses testing and QA, and Chapter 6 covers some of Node’s more important constructs and how they are extended and used by Express. Chapter 7 covers templating (using Handlebars), which lays the foundation of building useful websites with Express. Chapter 8 and Chapter 9 cover cookies, sessions, and form handlers, rounding out the things you need to know to build basic functional websites with Express.

Chapter 10 delves into middleware, a concept central to Express. Chapter 11 explains how to use middleware to send email from the server and discusses security and layout issues inherent to email.

Chapter 12 offers a preview into production concerns. Even though at this stage in the book you don’t have all the information you need to build a production-ready website, thinking about production now can save you from major headaches in the future.

Chapter 13 is about persistence, with a focus on MongoDB (one of the leading document databases) and PostgreSQL (a popular open-source relational database management system).

Chapter 14 gets into the details of routing with Express (how URLs are mapped to content), and Chapter 15 takes a diversion into writing APIs with Express. Chapter 17 covers the details of serving static content, with a focus on maximizing performance.

Chapter 18 discusses security: how to build authentication and authorization into your app (with a focus on using a third-party authentication provider), as well as how to run your site over HTTPS.

Chapter 19 explains how to integrate with third-party services. Examples used are Twitter, Google Maps, and the US National Weather Service.

Chapter 16 takes what we’ve learned about Express and uses it to refactor the running example as an SPA, with Express as the backend server providing the API we created in Chapter 15.

Chapter 20 and Chapter 21 get you ready for the big day: your site launch. They cover debugging, so you can root out any defects before launch, and the process of going live. Chapter 22 talks about the next important (and oft-neglected) phase: maintenance.

The book concludes with Chapter 23, which points you to additional resources, should you want to further your education about Node and Express, and where you can go to get help.

Example Website

Starting in Chapter 3, a running example will be used throughout the book: the Meadowlark Travel website. I wrote the first edition just after getting back from a trip to Lisbon, and I had travel on my mind, so the example website I chose is for a fictional travel company in my home state of Oregon (the Western Meadowlark is the state songbird of Oregon). Meadowlark Travel allows travelers to connect to local “amateur tour guides,” and it partners with companies offering bike and scooter rentals and local tours, with a focus on ecotourism.

Like any pedagogical example, the Meadowlark Travel website is contrived, but it is an example that covers many of the challenges facing real-world websites: third-party component integration, geolocation, ecommerce, performance, and security.

As the focus on this book is backend infrastructure, the example website will not be complete; it merely serves as a fictional example of a real-world website to provide depth and context to the examples. Presumably, you are working on your own website, and you can use the Meadowlark Travel example as a template for it.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This element signifies a tip or suggestion.

Note

This element signifies a general note.

Warning

This element indicates a warning or caution.

Using Code Examples

Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/EthanRBrown/web-development-with-node-and-express-2e.

This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Web Development with Node and Express, Second Edition by Ethan Brown (O’Reilly). Copyright 2019 Ethan Brown, 978-1-492-05351-4.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

O’Reilly Online Learning

Note

For almost 40 years, O’Reilly Media has provided technology and business training, knowledge, and insight to help companies succeed.

Our unique network of experts and innovators share their knowledge and expertise through books, articles, conferences, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, please visit http://oreilly.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

  • O’Reilly Media, Inc.
  • 1005 Gravenstein Highway North
  • Sebastopol, CA 95472
  • 800-998-9938 (in the United States or Canada)
  • 707-829-0515 (international or local)
  • 707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/web_dev_node_express_2e.

To comment or ask technical questions about this book, send email to .

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Acknowledgments

So many people in my life have played a part in making this book a reality; it would not have been possible without the influence of all the people who have touched my life and made me who I am today.

I would like to start out by thanking everyone at Pop Art: not only has my time at Pop Art given me a renewed passion for engineering, but I have learned so much from everyone there, and without their support, this book would not exist. I am grateful to Steve Rosenbaum for creating an inspiring place to work, and to Del Olds for bringing me on board, making me feel welcome, and being an honorable leader. Thanks to Paul Inman for his unwavering support and inspiring attitude toward engineering, and Tony Alferez for his warm support and for helping me carve out time for writing without impacting Pop Art. Finally, thanks to all the great engineers I have worked with, who keep me on my toes: John Skelton, Dylan Hallstrom, Greg Yung, Quinn Michaels, CJ Stritzel, Colwyn Fritze-Moor, Diana Holland, Sam Wilskey, Cory Buckley, and Damion Moyer.

I owe a great debt of gratitude to my current team at Value Management Strategies, Inc. I have learned so much about the business side of software from Robert Stewart and Greg Brink, and so much about team communication, cohesion, and effectiveness from Ashley Carson (thanks for your unwavering support, Scratch Chromatic). Terry Hays, Cheryl Kramer, and Eric Trimble, thank you all for your hard work and support! And thanks to Damon Yeutter, Tyler Brenton, and Brad Wells for their critical work on requirements analysis and project management. Most importantly, thank you to the talented and dedicated developers who have worked with me—tirelessly—at VMS: Adam Smith, Shane Ryan, Jeremy Loss, Dan Mace, Michael Meow, Julianne Soifer, Matt Nakatani, and Jake Feldmann.

Thanks to all of my bandmates at School of Rock! What a crazy journey it’s been and what a joyful creative outlet to have. Special thanks to the instructors who share their passion and knowledge of music: Josh Thomas, Amanda Sloane, Dave Coniglio, Dan Lee, Derek Blackstone, and Cory West. Thank you all for giving me the opportunity to be a rock star!

Zach Mason, thank you for being an inspiration to me. This book may be no The Lost Books of the Odyssey, but it is mine, and I don’t know if I would have been so bold without your example.

Elizabeth and Ezra, thank you for the gifts you both gave me. I will love you both forever.

I owe everything to my family. I couldn’t have wished for a better, more loving education than the one they gave me, and I see their exceptional parenting reflected in my sister too.

Many thanks to Simon St. Laurent for giving me this opportunity, and to Angela Rufino (second edition) and Brian Anderson (first edition) for their steady and encouraging editing. Thanks to everyone at O’Reilly for their dedication and passion. Thanks to Alejandra Olvera-Novack, Chetan Karande, Brian Sletten, Tamas Piros, Jennifer Pierce, Mike Wilson, Ray Villalobos, and Eric Elliot for their thorough and constructive technical reviews.

Katy Roberts and Hanna Nelson provided invaluable feedback and advice on my “over the transom” proposal that made this book possible. Thank you both so much! Thanks to Chris Cowell-Shah for his excellent feedback on the QA chapter.

Lastly, thanks to my dear friends, without whom I surely would have gone insane: Byron Clayton, Mark Booth, Katy Roberts, and Kimberly Christensen. I love you all.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.251.154