ebook img

Node Cookbook PDF

512 Pages·2020·13.787 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Node Cookbook

BFN eo Node Cookbook thuo anrtd yhe G E Node rdC Fourth Edition igi gstiooo n k b o A key technology for building web applications and tooling, Node.js brings JavaScript to the server o Cookbook enabling full-stack development in a common language. This fourth edition of the Node Cookbook k is updated with the latest Node.js features and the evolution of the Node.js framework ecosystems. This practical guide will help you to get started with creating, debugging, and deploying your Fourth Edition Node.js applications and cover solutions to common problems, along with tips to avoid pitfalls. You'll become familiar with the Node.js development model by learning how to handle fi les and build simple web applications and then explore established and emerging Node.js web frameworks such as Express.js and Fastify. As you advance, you'll discover techniques for detecting problems Discover solutions, techniques, and best practices in your applications, handling security concerns, and deploying your applications to the cloud. This recipe-based guide will help you to easily navigate through various core topics of server-side web for server-side web development with Node.js 14 application development with Node.js. By the end of this Node book, you'll be well-versed with core Node.js concepts and have gained the knowledge to start building performant and scalable Node.js applications. Things you will learn: • Understand the Node.js asynchronous • Discover tips for testing, optimizing, programming model and securing your web applications • Create simple Node.js applications • Create and deploy Node.js microservices using modules • Debug and diagnose issues in your • Develop simple web applications Node.js applications using web frameworks such as Express.js and Fastify Bethany Griggs Node Cookbook Fourth Edition Discover solutions, techniques, and best practices for server-side web development with Node.js 14 Bethany Griggs BIRMINGHAM—MUMBAI Node Cookbook Fourth Edition Copyright © 2020 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Commissioning Editor: Ashwin Nair Senior Editor: Sofi Rogers Content Development Editor: Mrudgandha Kulkarni Technical Editor: Shubham Sharma Copy Editor: Safis Editing Project Coordinator: Kinjal Bari Proofreader: Safis Editing Indexer: Priyanka Dhadke Production Designer: Aparna Bhagat First published: July 2012 Second edition: April 2014 Third edition: July 2017 Fourth edition: November 2020 Production reference: 1231120 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-83855-875-8 www.packt.com Packt.com Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website. Why subscribe? • Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals • Improve your learning with Skill Plans built especially for you • Get a free eBook or video every month • Fully searchable for easy access to vital information • Copy and paste, print, and bookmark content Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. Contributors About the author Bethany Griggs is a senior software engineer at Red Hat and a Node.js Technical Steering Committee member. Beth has been involved with the Node.js project since 2016 when she joined IBM's Node.js runtime team. Now at Red Hat, she is continuing her work on Node. js, including contributing to the Node.js project. Beth is an active member of the Node. js Release Working Group, who audit the content for and produce Node.js releases. Her other focuses include the creation of resources and tools to support Node.js deployments to the cloud. About the reviewer Dennis Myasnyankin is experienced in creating web scrapers that utilize Python and JavaScript to gather large amounts of data from various online resources. He has extracted a wide range of data, including small business specifics, video-game reviews, and travel agency contacts. Dennis has also sourced information through the scraping of IMDB details, Zillow listings, and cruise line information from targeted domains. Dennis has completed significant projects primarily through JavaScript, using the MERN tech-stack for building dynamic web applications, and Node.js's Puppeteer library to complete scraping tasks. He is interested in expanding his knowledge in other languages and new technologies while creating meaningful solutions to real-world problems. Packt is searching for authors like you If you're interested in becoming an author for Packt, please visit authors.packtpub. com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea. Table of Contents Preface 1 Introducing Node.js 14 Technical requirements 2 Getting ready 6 Installing Node.js 14 with nvm 2 How to do it… 6 How it works… 12 Getting ready 2 There's more… 13 How to do it… 2 How it works… 4 Adopting new JavaScript syntax There's more… 5 in Node.js 14 14 See also 5 Getting ready 14 Accessing the Node.js API How to do it… 15 documentation 5 How it works… 17 2 Handling I/O Technical requirements 20 There's more 25 Handling standard I/O 20 See also 31 Getting ready 20 Inspecting file metadata 32 How to do it 20 Getting ready 32 How it works 22 How to do it 32 See also 22 How it works 34 Managing files with fs module 22 There's more 36 See also 39 Getting ready 23 How to do it 23 Watching for file updates 39 How it works 24 Getting ready 39 ii Table of Contents How to do it 40 communication 43 How it works 41 Getting ready 43 See also 43 How to do it 44 How it works 45 Creating TCP server and client There's more 47 3 Streams, Streams, Streams Technical requirements 50 There's more… 67 Creating streams in Node.js 50 See also 67 Getting ready 51 Transforming data with How to do it… 51 transform streams 67 How it works… 54 Getting ready 68 There's more… 58 How to do it… 69 See also 61 How it works… 70 Interacting with paused streams 62 There's more… 71 See also 74 Getting ready 62 How to do it… 62 Building stream pipelines 75 How it works… 64 Getting ready 75 See also 65 How to do it… 76 Piping streams 65 How it works… 78 There's more… 79 Getting ready 65 See also 80 How to do it… 66 How it works… 66 4 Using Web Protocols Technical requirements 82 See also 86 Using http module to make Building an HTTP server to HTTP requests 82 accept GET requests 86 Getting ready 82 Getting ready 87 How to do it… 83 How to do it… 87 How it works… 85 How it works… 89 There's more… 86 Table of Contents iii There's more… 91 Using ws to create a WebSocket See also 91 server 106 Getting ready 107 Handling HTTP POST requests 91 How to do it… 107 Getting ready 92 How it works… 110 How to do it… 92 There's more… 110 How it works… 95 See also 112 There's more… 97 See also 99 Sending an automated email using your own SMTP server 112 Using formidable to handle file Getting ready 112 uploads 99 How to do it… 113 Getting ready 99 How it works… 114 How to do it… 100 There's more… 115 How it works… 103 See also 117 There's more… 104 See also 106 5 Developing Node.js modules Technical requirements 120 How to do it 136 Consuming Node.js modules 121 How it works 138 There's more 139 Getting ready 121 See also 140 How to do it 121 How it works 123 Preparing and publishing your There's more 127 module to npm 140 See also 130 Getting ready 140 Setting up your own module 130 How to do it 141 How it works 144 Getting ready 131 There's more 145 How to do it 131 How it works 134 Using ECMAScript modules 148 There's more 135 Getting ready 148 See also 135 How to do it 148 Implementing your module 136 How it works 150 See also 151 Getting ready 136

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.