Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Node Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Node Cookbook

Node Cookbook

By : David Mark Clements, Matteo Collina, Elger, Mathias Buus Madsen
4.7 (3)
close
close
Node Cookbook

Node Cookbook

4.7 (3)
By: David Mark Clements, Matteo Collina, Elger, Mathias Buus Madsen

Overview of this book

Today's web demands efficient real-time applications and scalability. Asynchronous event-driven programming is ideal for this, and this is where Node.js comes in. Server-side JavaScript has been here since the 90s, but Node got it right. With Node for tooling and server-side logic, and a browser-based client-side UI, everything is JavaScript. This leads to rapid, fluid development cycles. The full-stack, single language experience means less context-switching between languages for developers, architects and whole teams. This book shows you how to build fast, efficient, and scalable client-server solutions using the latest versions of Node. The book begins with debugging tips and tricks of the trade, and how to write your own modules. Then you'll learn the fundamentals of streams in Node.js, discover I/O control, and how to implement the different web protocols. You'll find recipes for integrating databases such as MongoDB, MySQL/MariaDB, Postgres, Redis, and LevelDB. We also cover the options for building web application with Express, Hapi and Koa. You will then learn about security essentials in Node.js and advanced optimization tools and techniques. By the end of the book you will have acquired the level of expertise to build production-ready and scalable Node.js systems. The techniques and skills you will learn in this book are based on the best practices developed by nearForm, one of the leaders in Node implementations, who supported the work of the authors on this book.
Table of Contents (12 chapters)
close
close

Creating a Koa web app

Koa is an evolution of the middleware concept in line with updates to the JavaScript language. Originally in Koa-v1, flow control was handled by re-purposing ECMAScript 2015 (ES6) Generator functions (using the yield keyword to freeze function execution) combined with promises. In Koa-v2, a more normative route is taken using ES 2016 async/await syntax.

It's a minimalist web framework compared to Express (and far more minimalist compared to Hapi). Koa is more closely comparable to the Connect web framework (which was the precursor to Express). This means that functionality that tends to come as standard in other web frameworks (such as route handling) is installed separately as Koa middleware.

In this recipe, we're going to create a Koa (v2) web application.

Node 8+ Only
This recipe focuses on Koa-v2, using up-to-date async/await syntax, which is...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY