1. Trang chủ
  2. » Kinh Doanh - Tiếp Thị

Node js 8 the right way practical, server side javascript that scales

323 7 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Early praise for Node.js the Right Way Node.js the Right Way is an excellent guide for building robust Node.js applications and making use of the extensive Node.js ecosystem Using realistic applications from several different domains, it gives a highly useful and thorough description of the process of building, testing, and deploying real-world Node.js programs ➤ Dan Scales Principal Engineer, Google Inc Without the original Node.js the Right Way, I wouldn’t be where I am today This book leapfrogged me from being a casual Node.js developer to loving the event loop and knowing how to build effective distributed systems in Node.js It led me to writing clean, idiomatic, and highly understandable JavaScript—both in Node.js and in the browser This update will the same for readers ➤ Kyle Kelley Senior Software Engineer, Netflix Jim’s update to his engaging, wide-ranging deep dive into how to solve actual problems using Node.js taught even this old dog some new tricks Hats off to Jim for clearly demonstrating how to get the most out of Node.js ➤ Mark Trostler Software Engineer, Google Inc Jim Wilson shows the correct way, the way that will definitely make you a better Node.js developer, giving you many techniques, insights, and—most of all—some really cool stuff Node.js the Right Way provides loads of good practices and reveals some of the lower-level interactions of Node with the system In a Node.js shop, this book is a must for seniors’ reference and a must for new hires ➤ Peter Perlepes Software Engineer, Growth Node.js the Right Way Practical, Server-Side JavaScript That Scales Jim R Wilson The Pragmatic Bookshelf Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trademarks of The Pragmatic Programmers, LLC Every precaution was taken in the preparation of this book However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein Our Pragmatic books, screencasts, and audio books can help you and your team create better software and have more fun Visit us at https://pragprog.com The team that produced this book includes: Publisher: Andy Hunt VP of Operations: Janet Furlow Managing Editor: Brian MacDonald Supervising Editor: Jacquelyn Carter Copy Editor: Candace Cunningham Indexing: Potomac Indexing, LLC Layout: Gilson Graphics For sales, volume licensing, and support, please contact support@pragprog.com For international rights, please contact rights@pragprog.com Copyright © 2018 The Pragmatic Programmers, LLC All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher Printed in the United States of America ISBN-13: 978-1-68050-195-7 Encoded using the finest acid-free high-entropy binary digits Book version: P1.0—January 2018 Contents Acknowledgments Preface ix xi 3 Part I — Getting Up to Speed on Node.js Getting Started Thinking Beyond the web Node.js’s Niche How Node.js Applications Work Aspects of Node.js Development Installing Node.js Wrangling the File System Programming for the Node.js Event Loop Spawning a Child Process Capturing Data from an EventEmitter Reading and Writing Files Asynchronously The Two Phases of a Node.js Program Wrapping Up 11 11 16 17 20 23 24 Networking with Sockets Listening for Socket Connections Implementing a Messaging Protocol Creating Socket Client Connections Testing Network Application Functionality Extending Core Classes in Custom Modules Developing Unit Tests with Mocha Wrapping Up 27 28 32 35 36 38 43 49 Connecting Robust Microservices Installing ØMQ Publishing and Subscribing to Messages Responding to Requests Routing and Dealing Messages Clustering Node.js Processes Pushing and Pulling Messages Wrapping Up Contents • vi 53 54 58 62 66 68 73 76 81 83 85 91 100 104 108 Part II — Working with Data Transforming Data and Testing Continuously Procuring External Data Behavior-Driven Development with Mocha and Chai Extracting Data from XML with Cheerio Processing Data Files Sequentially Debugging Tests with Chrome DevTools Wrapping Up Commanding Databases Introducing Elasticsearch Creating a Command-Line Program in Node.js with Commander Using request to Fetch JSON over HTTP Shaping JSON with jq Inserting Elasticsearch Documents in Bulk Implementing an Elasticsearch Query Command Wrapping Up 111 112 114 121 126 130 133 142 Part III — Creating an Application from the Ground Up Developing RESTful Web Services Advantages of Express Serving APIs with Express Writing Modular Express Services Keeping Services Running with nodemon Adding Search APIs Simplifying Code Flows with Promises Manipulating Documents RESTfully Emulating Synchronous Style with async and await 147 148 149 151 155 155 161 167 171 Contents Providing an Async Handler Function to Express Wrapping Up • vii 172 181 Creating a Beautiful User Experience Getting Started with webpack Generating Your First webpack Bundle Sprucing Up Your UI with Bootstrap Bringing in Bootstrap JavaScript and jQuery Transpiling with TypeScript Templating HTML with Handlebars Implementing hashChange Navigation Listing Objects in a View Saving Data with a Form Wrapping Up Fortifying Your Application Setting Up the Initial Project Managing User Sessions in Express Adding Authentication UI Elements Setting Up Passport Authenticating with Facebook, Twitter, and Google Composing an Express Router Bringing in the Book Bundle UI Serving in Production Wrapping Up 185 186 190 192 196 197 201 205 207 212 216 219 220 225 227 229 234 246 251 253 256 10 BONUS: Developing Flows with Node-RED Setting Up Node-RED Securing Node-RED Developing a Node-RED Flow Creating HTTP APIs with Node-RED Handling Errors in Node-RED Flows Wrapping Up 259 260 261 262 266 276 283 A1 Setting Up Angular A2 Setting Up React Index 285 291 295 Acknowledgments I’m so grateful to have had the opportunity to write this book And I’m especially thankful for my editor, Jackie Carter—your thoughtful feedback made this book what it is today Thank you, dear reader, and readers of the Beta releases Your errata reports made the book better than it would have otherwise been I’d also sincerely like to thank the whole team at The Pragmatic Bookshelf Thanks for your kind patience, and all of your hard work to polish this book and find all of my mistakes I’d like to thank all of my reviewers Your keen observations have helped make this book even more technically correct (the best kind of correct) In no particular order: Dan Scales Mark Ethan Trostler Gary Chamberlain Rick Waldron Nick Capito Peter Hampton Luca Mezzalira Peter Perlepes Dominic Schulz Maricris S Nonato And I want to thank my amazing family, too Dear Ruthy, you are my inspiration; never stop fighting! Emma and Jimmy, even though you’re both growing up too fast, I can’t wait to see all the great things you’ll For anyone I missed, I hope you’ll accept my apologies Any omissions were certainly not intentional, and I have nothing but gratitude for you in my heart report erratum • discuss ... Early praise for Node.js the Right Way Node.js the Right Way is an excellent guide for building robust Node.js applications and making use of the extensive Node.js ecosystem Using realistic... Software Engineer, Growth Node.js the Right Way Practical, Server-Side JavaScript That Scales Jim R Wilson The Pragmatic Bookshelf Raleigh, North Carolina Many of the designations used by manufacturers... everything The community of Node.js developers, the conventions in Node.js development, and even the semantics of the JavaScript language itself are all rapidly evolving With eyes to the near future, the

Ngày đăng: 27/09/2021, 15:41

Xem thêm:

Mục lục

    Why Node.js the Right Way?

    What’s in This Book

    What This Book Is Not

    Code Examples and Conventions

    Thinking Beyond the web

    2. Wrangling the File System

    Spawning a Child Process

    Capturing Data from an EventEmitter

    Reading and Writing Files Asynchronously

    Listening for Socket Connections

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w