Share E-Book

Conquering JavaScript Node.js (Sufyan bin Uzayr) (z-library.sk, 1lib.sk, z-lib.sk)

Author

Rating 3.5 AI initial rating

Log in to rate

JavaScript
Language English

JavaScript is without a question among the most prominent and commonly used client-side programming languages available. JavaScript's scope of use has expanded in recent years, and it is now also used for server-side development. Node.js is an extremely popular JS framework, meant for rapid web and application development. Conquering JavaScript: Node.js helps the reader master the Node.js framework for faster and more robust development. This book is a detailed guide that will help developers and coders do more with Node.js. It discusses the basics in brief, and then moves on to more advanced and detailed exercises to help readers quickly gain the required knowledge. Key Features: Discusses how to use Node.js for real-world practical solutions Provides complete coverage of full-stack development Covers server-side development with Node.js This book is a valuable reference for Node.js developers as well as those involved in game development, mobile apps, progressive applications, and now even desktop apps.

Format PDF
Size 7.7 MB
(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.

Page 1
(This page has no text content)
Page 2
Conquering JavaScript JavaScript is without a question among the most prominent and commonly used client-side programming languages available. JavaScript’s scope of use has expand- ed in recent years, and it is now also used for server-side development. Node.js is an extremely popular JS framework, meant for rapid web and application develop- ment. Conquering JavaScript: Node.js helps the reader master the Node.js framework for faster and more robust development. The book is a detailed guide that will help developers and coders do more with Node.js. It discusses the basics in brief, and then moves on to more advanced and detailed exercises to help readers quickly gain the required knowledge. Key Features: • Discusses how to use Node.js for real-world practical solutions • Provides complete coverage of full-stack development • Covers server-side development with Node.js This book is a valuable reference for Node.js developers as well as those involved in game development, mobile apps, progressive applications, and now even desktop apps.
Page 3
About the Series The Conquering JavaScript series covers a wide range of topics, pertain- ing specifically to the JavaScript programming ecosystem, such as frame- works and libraries. Each book of this series is focused on a singular topic, and covers the said topic at length, focusing especially on real-world usage and code-oriented approach, adhering to an industry-standard coding paradigm, so as to help the learners gain practical expertise that can be useful for real-world projects. Some of the key aspects of books in this series are: • Crystal-clear text, spanning various JavaScript-related topics sorted by relevance. • Special focus on practical exercises with numerous code samples and programs. • A guided approach to JS coding with step-by-step tutorials and walkthroughs. • Keen emphasis on the real-world utility of skills, thereby cutting the redundant and seldom-used concepts and bloatware. • A wide range of references and resources to help the readers gain the most out of the books. The Conquering JavaScript series of books assume a basic understanding of coding fundamentals. Conquering JavaScript is edited by Sufyan bin Uzayr, a writer and edu- cator having over a decade of experience in the computing field. Sufyan holds multiple degrees, and has taught at universities and institutions worldwide. Having authored and edited over 50 books thus far, Sufyan brings a wide array of experience to the series. Learn more about his works at sufyanism.com. https://www.routledge.com/Conquering-JavaScript/book-series/ CRCCONJAV
Page 4
Conquering JavaScript Node.js Edited by Sufyan bin Uzayr
Page 5
First edition published [2024] by CRC Press 2385 Executive Center Drive, Suite 320, Boca Raton, FL 33431 and by CRC Press 4 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN CRC Press is an imprint of Taylor & Francis Group, LLC © 2024 Sufyan bin Uzayr Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please contact mpkbookspermissions@tandf. co.uk Trademark Notice: Product or corporate names may be trademarks or registered trademarks and are used only for identification and explanation without intent to infringe. Library of Congress Cataloging‑in‑Publication Data Names: Bin Uzayr, Sufyan, editor. Title: Conquering javascript : node.js / edited by Sufyan bin Uzayr. Description: Boca Raton : CRC Press, 2024. | Series: Conquering javascript | Includes bibliographical references and index. Identifiers: LCCN 2023007166 (print) | LCCN 2023007167 (ebook) | ISBN 9781032413136 (paperback) | ISBN 9781032413150 (hardback) | ISBN 9781003357469 (ebook) Subjects: LCSH: JavaScript (Computer program language) | Node.js. | Application software--Development. Classification: LCC QA76.73.J39 C655 2024 (print) | LCC QA76.73.J39 (ebook) | DDC 005.2/762--dc23/eng/20230420 LC record available at https://lccn.loc.gov/2023007166 LC ebook record available at https://lccn.loc.gov/2023007167 ISBN: 9781032413150 (hbk) ISBN: 9781032413136 (pbk) ISBN: 9781003357469 (ebk) DOI: 10.1201/9781003357469 Typeset in Minion by KnowledgeWorks Global Ltd.
Page 6
For Dad
Page 7
(This page has no text content)
Page 8
vii Contents About the Editor, xvii Acknowledgments, xviii Zeba Academy – Conquering JavaScript, xix Chapter 1 ◾ Introduction 1 ENVIRONMENT SETUP FOR NODE.JS 6 Setup of the Local Environment 6 Editor of Text 7 The Runtime for Node.js 7 The Node.js Archive Can Be Downloaded Here 7 UNIX/LINUX/MAC OS X AND SUNOS INSTALLATIONS 7 Windows Installation 7 Node.js Has a Number of Features 8 Who Makes Use of Node.js? 8 When Should You Use Node.js? 8 THE BENEFITS OF NODE.JS 9 Scalability Is Straightforward with Node.js 9 Simple to Comprehend 9 The Computer Language Node.js Is Used as a Single Programming Language 10 Full-Stack JS Node’s Advantages 10 Recognized for Delivering Exceptional Results 10
Page 9
viii ◾ Contents A Large and Active Group Node Provides Community Support 10 The Advantages of Caching 10 Allows You to Build Own Applications 11 Handles a Large Number of Requests at Once 11 Node.js Is a Framework with a Lot of Flexibility 11 DISADVANTAGES OF NODE.JS 11 API Instability: Significant Code Changes as a Result of Unstable API 11 Your Code May Be Jeopardized If You Do Not Have a Library Support System 11 Code That Is Difficult to Maintain 12 When Performing Heavy Computing Tasks, Performance Is Reduced 12 CORE CONCEPT 12 There Are a Lot of Libraries 13 A BRIEF OVERVIEW OF NODE.JS’S HISTORY 13 How to Install Node.js 14 To Use Node.js, How Much JavaScript Do You Need to Know? 15 NODE.JS AND THE BROWSER: WHAT’S THE DIFFERENCE? 16 The Ecosystem Is What Changes 16 WEB APPLICATION ARCHITECTURE WITH NODE.JS 17 Node.js Server Architecture 17 Asynchronous Model 17 Avoid Using Synchronous Functions and Instead Use Asynchronous Ones 19 Callbacks 20 Emitters of Events 20 There’s a Catch with Asynchronous Code 20 Nonblocking I/O Operations 21 Callbacks 21
Page 10
Contents ◾ ix IS NODE.JS A FRONTEND OR A BACKEND FRAMEWORK? 23 WHEN SHOULD NODE.JS BE USED? 24 FRAMEWORKS FOR NODE.JS AND ITS VARIOUS FORMS 25 MVC (Model View Controller) Framework 25 MVC Frameworks That Cover the Entire Stack 25 Frameworks for REST APIs 25 Express.js 25 Koa.js 25 Socket.io 26 Hapi.js 26 HOW DOES ONE PICK A NODE.JS HOSTING SERVICE? 26 Amazon Web Services 26 Google Cloud Platform 27 Heroku 27 Microsoft Azure 28 RedHat OpenShift Online 28 ZEIT 28 DigitalOcean 29 THE V8 JAVASCRIPT ENGINE 29 Other JS Frameworks 29 The Pursuit of Excellence 30 Compilation 30 Use the Command Line to Run Node.js Programs 30 Automatically Restart the Application 31 WHAT IS THE BEST WAY TO END A NODE.JS PROGRAM? 32 RECAP OF BASICS 33 SUMMARY 34 NOTES 34 Chapter 2 ◾ Application Development I 35 BUILDING APPLICATION WITH NODE.JS 36 What Are WebSockets and How Do I Use Them? 36
Page 11
x ◾ Contents Definition of WebSockets 36 What Are WebSockets and How Do They Work? 36 REQUIREMENTS 37 IN NODE.JS, HOW DO YOU MAKE A WEBSOCKETS API? 37 UndeRESTimated 37 Single Point of Failure (at the Point of Entry) 38 As a Contract, the Message 39 Internal Communication 41 HTTP versus WebSockets 43 Building a Chat Room App with Socket.io Tutorial 43 CODE TUTORIAL 44 WHAT SOCKET.IO IS NOT? 44 You Must Now Prepare the Frontend Portion 45 SUMMARY 53 Chapter 3 ◾ Application Development II 55 STEP 1: PERFORM A MARKET STUDY 56 Music Streaming Apps 56 eSports Streaming Apps 57 STEP 2: IDENTIFYING CHARACTERISTICS 57 Basic Characteristics 57 Optional Extras 58 STEP 3: COMPLETION OF THE TECH STACK 58 Protocols for Online Video Streaming 59 MPEG-DASH 59 HLS 59 RTMP 59 WebRTC 60 PLATFORMS FOR STREAMING 60 CONTENT DISTRIBUTION NETWORKS 61 Database and Hosting 62 STEP 4: DEVELOPMENT AND DESIGN 62
Page 12
Contents ◾ xi STEP 5: TESTING AND UPKEEP 63 WHAT DOES IT COST TO CREATE A STREAMING APPLICATION? 64 Costs Dependent on Features 64 APPLICATION DEVELOPMENT USING NODE.JS 64 Streams for Video Games 64 What Exactly Are Streams? 65 A Real-Life Example 66 Iterator in Asynchronous Fashion 66 Reading Modes 68 What Is the Most Effective Method for Creating a Writable Stream? 70 Pipeline () 72 The Stream Module 73 Node APIs with Streams 73 OVERVIEW OF THE PROJECT 75 Advantages and Disadvantages of the Application 75 CODE TUTORIAL 75 The /Video Endpoint 76 Identifying the Range 78 Creating Headers for Responses 79 SUMMARY 81 Chapter 4 ◾ Application Development III 83 WHY IS NODE.JS THE BEST IOT SOLUTION? 83 WHAT EXACTLY ARE THE ADVANTAGES OF NODE.JS FOR IOT? 84 Application Development Using Node.js 84 IoT Protocols Are Simple to Integrate with Node.js 84 Node.js Is a Powerful and Quick Programming Language 85 Node.js Is a Scalable and Resource-Efficient Programming Language 85
Page 13
xii ◾ Contents Data Security Is Provided by Node.js 85 Authentication That Is Safe 86 It’s Easy to Create APIs with Node.js 86 Where Can I Begin Developing an IoT Project in Node.js? 86 How Do You Pick the Best Database for IoT? 87 How to Make Big Data Work for IoT Projects 88 The Project’s Future Architecture Will Be Able to Grow with It 89 The Work with the Project’s Code Is the Next Step in Optimization 89 Real-Time IoT Analytics 89 What Are Some Examples of Node.js-Based IoT Apps? 90 Uber 90 Code Tutorial 91 The Schema’s Design 92 Geospatial Indexes in MongoDB 97 SUMMARY 103 Chapter 5 ◾ Code Optimization 105 WHAT MAKES NODE.JS PERFORMANCE SO SPECIAL? 106 Run-to-Completion, Single-Threaded Behavior 106 Detecting Memory Leaks 106 WHAT IS AN EVENT LOOP AND HOW DOES IT WORK? 107 THE EVENT LOOP AND NODE.JS PERFORMANCE 107 Setting Up, Running, and Analyzing a Performance Test for Node.js Application 107 Creating a Performance Test Profile in Node.js 108 Duplicating Large-Scale Distributed Systems 109 Configuring Our Monitoring 109 Setting Up a Node.js Performance Test Environment 110 Running Our Tests 110 How to Make Node.js Run Faster 110
Page 14
Contents ◾ xiii Tooling for the Frontend 110 Task Runners and Module Bundlers 110 Modules and Preprocessors for CSS 111 Images 111 HTTP/2 and SSL/TLS 111 Using Caching 112 Improving Data Management Techniques 113 WHAT IS THE MOST EFFICIENT WAY TO ACHIEVE THIS? 113 Load Balancing 114 Client-Side Authentication That Is Secure 115 Maintaining a Lightweight and Compact Code 115 Effective Server Communication with WebSockets 116 Coding That Is Asynchronous 116 Synchronous 117 Asynchronous 117 Query Augmentation 117 OVERVIEW OF BASIC STRATEGIES FOR IMPROVING DATABASE PERFORMANCE/OPTIMIZATION 118 SELECT Should Be Avoided at All Costs 118 Use the WHERE Clause 118 To Sample the Query Results, Use LIMIT 118 Avoid CHOOSE A UNIQUE OPTION 119 Use the Wildcard (Percent) Character as Needed 119 Using Off-Peak Hours to Run Queries 120 GO WITHOUT A SESSION 120 Tracing and Logging of Scripts 120 Winston 120 Morgan 121 Bunyan 121 Parallelism 121
Page 15
xiv ◾ Contents NODE.JS ENCRYPTION GUIDELINES 122 Why Are There Security Issues with Node.js? 122 TOP NODE.JS SECURITY CONCERNS AND RECOMMENDATIONS 122 Validate User Inputs to Limit XSS Attacks 122 Data Leaks Should Be Avoided at All Costs 123 Make Use of Security Linters 123 Each Request Should Have Access Control Implemented 123 Deserialization Using Encryption 124 HTTP Response Headers Are Executed 124 Create a Logging and Monitoring System 125 Authentication Should Be Strong and Thorough 125 Scan Apps for Vulnerabilities on a Regular Basis 126 Build Pipelines for Security Patches Using Fluid 126 GENERAL TIPS 127 Look at Our Naming Conventions 127 Where Functions Should Be Modularized 128 Commenting in the Right Way 128 When Debugging, Be Aware of the Context 128 Destructuring 129 Do Not Make the Same Mistake Twice 129 Callback Etiquette 129 ALWAYS DOUBLE-CHECK CALLBACKS FOR PROBLEMS 129 On Callbacks, Return 130 Only Use Try-Catch in Sync Code 131 As Much as Possible Keep Away from It 131 Make Effective Use of Async Patterns 132 ERROR CORRECTION 132 Errors in Operations 132 Taking Care of Operational Errors 132
Page 16
Contents ◾ xv Errors in Programming 132 Referred to as an Async 132 Taking Care of Programmer Faults 133 SUMMARY 133 NOTES 134 Chapter 6 ◾ Summary 135 CAREER PROSPECTS OF NODE.JS 135 USING NODE.JS WITH OTHER FRAMEWORKS AND TOOLS 137 WHAT ARE THE ADVANTAGES OF UTILIZING NODE.JS FRAMEWORKS? 138 JS Frameworks and Their Types 138 FRAMEWORKS FOR WEB APP DEVELOPMENT USING NODE.JS 138 Loopback 142 Adonis 142 Total 143 HOW DO WE PICK THE BEST FRAMEWORK FOR OUR WEB APPS? 143 IS NODE.JS COMPATIBLE WITH REACT? 144 WHY USE NODE.JS AND REACT TOGETHER FOR WEB APP DEVELOPMENT? 144 HOW TO CREATE AN ANGULAR APP USING NODE.JS 146 Introduction 146 Prerequisites 146 Project Exercising 146 Phase of Development 147 Structure of the Project 147 API for Node.js 148
Page 17
xvi ◾ Contents ANGULAR APPLICATION 149 The Angular and Node APIs Work Together 152 How to Create a Production-Ready Project 152 SUMMARY 153 BIBLIOGRAPHY, 155 INDEX, 159
Page 18
xvii About the Editor Sufyan bin Uzayr is a writer, coder, and entrepreneur having over a decade of experience in the industry. He has authored several books in the past, pertaining to a diverse range of topics, ranging from History to Computers/IT. Sufyan is the Director of Parakozm, a multinational IT company spe- cializing in EdTech solutions. He also runs Zeba Academy, an online learning and teaching vertical with a focus on STEM fields. Sufyan specializes in a wide variety of technologies, such as JavaScript, Dart, WordPress, Drupal, Linux, and Python. He holds multiple degrees, including ones in Management, IT, Literature, and Political Science. Sufyan is a digital nomad, dividing his time between four countries. He has lived and taught in numerous universities and educational institutions around the globe. Sufyan takes a keen interest in technology, politics, lit- erature, history, and sports, and in his spare time, he enjoys teaching cod- ing and English to young students. Learn more at sufyanism.com
Page 19
xviii Acknowledgments There are many people who deserve being on this page because this book would not have come into existence without their support. That said, some names deserve a special mention, and I am genuinely grateful to: • My parents, for everything they have done for me. • The Parakozm team, especially Divya Sachdeva, Jaskiran Kaur, and Simran Rao, for offering great amounts of help and assistance during the book-writing process. • The CRC team, especially Sean Connelly and Danielle Zarfati, for ensuring that the book’s content, layout, formatting, and everything else remain perfect throughout. • Reviewers of this book, for going through the manuscript and pro- viding their insight and feedback. • Typesetters, cover designers, printers, and everyone else, for their part in the development of this book. • All the folks associated with Zeba Academy, either directly or indi- rectly, for their help and support. • The programming community in general, and the web development community, in particular, for all their hard work and efforts. Sufyan bin Uzayr
Page 20
xix Zeba Academy – Conquering JavaScript The “Conquering JavaScript” series of books are authored by the Zeba Academy team members, led by Sufyan bin Uzayr, consisting of: • Divya Sachdeva • Jaskiran Kaur • Simran Rao • Aruqqa Khateib • Suleymen Fez • Ibbi Yasmin • Alexander Izbassar Zeba Academy is an EdTech venture that develops courses and content for learners primarily in STEM fields and offers educational consulting and mentorship to learners and educators worldwide. Additionally, Zeba Academy is actively engaged in running IT Schools in the CIS countries and is currently working in partnership with numerous universities and institutions. For more info, please visit https://zeba.academy
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List