node.js 8 the right wayfiles.isec.pt/documentos/servicos/biblio/sumarios_monografia… ·...

4
Node.js 8 the Right Way Practical, Server-Síde JavaScript That Scales Jim R. Wilson The Pragmatíc.Bookshelf Ralelgh. North Carolma

Upload: others

Post on 26-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Node.js 8 the Right Wayfiles.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/Sumarios_Monografia… · Authenticating wíth Facebook, Twítter, and Google 234 Composing an Express Router 246 Brtngíng

Node.js 8 the Right WayPractical, Server-Síde JavaScript That Scales

Jim R.Wilson

The Pragmatíc.BookshelfRalelgh. North Carolma

Page 2: Node.js 8 the Right Wayfiles.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/Sumarios_Monografia… · Authenticating wíth Facebook, Twítter, and Google 234 Composing an Express Router 246 Brtngíng

Contents

Acknowledgments ixPreface xi

Part I - Getting Up to Speed on Node.js 8l. Getting Started 3

Thinking Beyond the web 3Node.js's Niche 5How Node.js Applications Work 6Aspects of Node.js Development 8Installing Node.js 9

2. Wrangling the File System 11Programrníng for the Node.js Event Loop 11Spawning a Child Process 16Capturing Data from an EventEmitter 17Reading and Wrttíng Files Asynchronously 20The Two Phases of a Node.js Program 23Wrappíng Up 24

3. Networking with Sockets 27Listening for Socket Connections 28Implementing a Messagíng Protocol 32Creating Socket Client Connections 35Testing Network Application Functíonalíty 36Extending Core Classes in Custom Modules 38Developing UnU Tests wíth Mocha 43Wrapping Up 49

Page 3: Node.js 8 the Right Wayfiles.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/Sumarios_Monografia… · Authenticating wíth Facebook, Twítter, and Google 234 Composing an Express Router 246 Brtngíng

Contents • vi

4. Connecting Robust Microservices 53Installing 0MQ 54Publishing and Subscribing to Messages 58Respondíng to Requests 62Routíng and Dealing Messages 66Clusteríng Node.js Processes 68Pushíng and Pulling Messages 73Wrapping Up 76

Part 11- Working with Data

5. Transforming Data and Testing Continuously 81Procuring External Data 83Behavíor- Driven Development wíth Mocha and Chai 85Extracting Data from XML with Cheerío 91Processing Data Files Sequentially 100Debuggíng Tests with Chrome DevTools 104Wrapping Up 108

6. Commanding Databases lUIntroducing Elasticsearch 112Creatíng a Command-Líne Prograrn ín Node.jswíth Commander 114Using request to Fetch JSON over HTfP 121Shaping JSON with jq 126Inserting Elasticsearch Documents ín Bulk 130Implementing an Elasticsearch Query Command 133Wrapping Up 142

Part 11I- Creating an Application from the Ground Up

7. Developing RESTful Web Services 147Advantages of Express 148Serving APIs with Express 149Wrítíng Modular Express Services 151Keeping Services Running with nodemon 155Addlng Search APIs 155Símplífyíng Code Flows with Promises 161Manípulatíng Documents RESTfully 167Emulating Synchronous Style wíth async and awaít 171

Page 4: Node.js 8 the Right Wayfiles.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/Sumarios_Monografia… · Authenticating wíth Facebook, Twítter, and Google 234 Composing an Express Router 246 Brtngíng

Contents • vii

Providing an Async Handler Function to Express 172Wrapping Up 181

8. Creatíng a Beautiful User Experience 185Getting Started with webpack 186Generating Your First webpack Bundle 190Sprucíng Up Your DI with Bootstrap 192Bríngíng in Bootstrap JavaScript and jQuery 196Transpiling wíth TypeScript 197Templattng HTML wíth Handlebars 201lmplementíng hashChange Navígatíon 205Listing Objects in a View 207Saving Data with a Form 212Wrapping Up 216

9. Fortifying Your Application 219Settíng Up the Inítíal Project 220Managíng User Sessions in Express 225Addíng Authentication DI Elements 227Settíng Up Passport 229Authenticating wíth Facebook, Twítter, and Google 234Composing an Express Router 246Brtngíng in the Book Bundle DI 251Servíng in Production 253Wrapping Up 256

10. BONUS: Developing Flows with Node-RED 259Setting Up Node-RED 260Securing Node-RED 261Developing a Node-RED Flow 262Creatíng HTfP APIs with Node-RED 266Handling Errors in Node-RED Flows 276Wrapping Up 283

AI. Setting Up Angular 285A2. Setting Up React 291

Index 295