Server Side development with Node.js and Koa.js Quick Start Guide - Olayinka Omole - E-Book

Server Side development with Node.js and Koa.js Quick Start Guide E-Book

Olayinka Omole

0,0
28,14 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Build real-world robust web applications and APIs using the modern and expressive Koa Node.js framework.




Key Features



  • Get up and running with Koa.js and leverage its power with node.js


  • Get the most out of Koa Async functions and generators


  • Create real time dynamic serverside apps efficiently with Koa.js



Book Description



Every developer wants to build modular and scalable web applications. Modern versions of JavaScript have made this possible in Node.js, and Koa is a Node.js framework that makes it easy. This book is the ideal introduction for JavaScript developers who want to create scalable server side applications using Node.js and Koa.js.






The book shows you how Koa can be used to start projects from scratch, register custom and existing middleware, read requests, and send responses to users. We will explore the core concepts in Koa, such as error handling, logging, and request and response handling. We will dive into new concepts in JavaScript development, and see how paradigms such as async/await help with modern Node.js application development.






By the end of this book, you will be building robust web applications in Koa using modern development paradigms and techniques of Node.js development.





What you will learn



  • Create a simple server in Node.js and Koa


  • Work with custom middleware in Koa


  • Handle errors in Koa


  • Create routes, handle requests, and send responses from APIs


  • Build views and use templates in Koa


  • Authenticate your application and structure it properly in Koa





Who this book is for



This book is for serverside developers and JavaScript developers who want to use Koa.js and Node.js to create fast and real time back end applications.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 125

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Server Side Development with Node.js and Koa.js Quick Start Guide

 

Build robust and scalable web applications with modern JavaScript techniques

 

 

 

 

 

 

 

 

 

 

 

 

 

Olayinka Omole

 

 

 

 

 

 

 

 

 

 

BIRMINGHAM - MUMBAI

Server Side Development with Node.js and Koa.js Quick Start Guide

Copyright © 2018 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(s), 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:Amarabha BanerjeeAcquisition Editor: Reshma RamanContent Development Editor:Smit CarvalhoTechnical Editor: Sushmeeta JenaCopy Editor:Safis EditingProject Coordinator: Hardik BhindeProofreader: Safis EditingIndexer:Mariammal ChettiyarGraphics: Alishon MendonsaProduction Coordinator:Shraddha Falebhai

First published: November 2018

Production reference: 1291118

Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK.

ISBN  978-1-78934-539-1

www.packtpub.com

 
mapt.io

Mapt is an online digital library that gives you full access to over 5,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

Mapt is fully searchable

Copy and paste, print, and bookmark content

Packt.com

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 www.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

Olayinka Omole is a software engineer currently based in London who grew up in Lagos, Nigeria. He is self-taught and primarily enjoys building with JavaScript, Python, PHP, and Java. He has written a lot about these technologies in multiple blogs and publications, including Sitepoint, and Scotch.io. He spends most of his time doing the usual fun things—writing code, learning how to write more code, and watching TV shows. His background in electrical and electronic engineering ensures that his passion for embedded engineering and DIY projects is also kept alive.

About the reviewer

Bhanu Pratap Chaudhary is a self-taught programmer who has been active in the JavaScript ecosystem for around five years now. After working as a consultant, freelancer, engineer, lead, and CTO in various start-ups, he is working on an already profitable stealth-mode B2B start-up in the catering industry.

He can also be found boxing, listening to and writing music, and he loves to write simple and readable code.

 

 

 

 

 

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

Title Page

Copyright and Credits

Server Side Development with Node.js and Koa.js Quick Start Guide

About Packt

Why subscribe?

Packt.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Download the color images

Code in action

Conventions used

Get in touch

Reviews

Introducing Koa

Technical requirements

What is Koa?

What can you do with Koa?

Why choose Koa?

When you should not use Koa

Koa versus Express

How can this book help you understand Koa better?

Summary

Getting Started with Koa

Technical requirements

Modern JavaScript

A primer on Node

What is async… await?

The promise class

Introducing async

Introducing await

Installing Koa

Using Babel

Starting a server in Koa

Summary

Koa Core Concepts

Technical requirements

The application object

Useful application methods

Settings

The context object

Context object API

Aliases

The request object

Content negotiation

The response object

Middleware

Cascading in Koa

Defining middleware

Registering middleware

Common middleware

Summary

Handling Errors in Koa

Technical requirements

Catching errors in Koa

Koa's default error handler

Emitting errors

Error event listener

Throwing HTTP errors

Writing error handlers

Summary

Building an API in Koa

Technical requirements

Project setup

Initialization

Installing dependencies

Structure

Building the application

Starting the server

Using Nodemon

Connecting to a database

Creating data models

Setting up the router

Setting up a logger

Creating contact endpoints and controller actions

Retrieving all contacts

Storing new contacts

Retrieving a single contact

Updating a contact

Deleting a contact

Validating requests

Useful notes

Summary

Building an Application in Koa

Technical requirements

About the application

Setting up a project

Installing dependencies

Project structure

Building the application

Starting the server

Connecting to the database

Creating data models

The user model

The post model

Setting up the router

Setting up the views

Using partials

Setting up sessions

Handling authentication

User registration and login

Authentication middleware

Creating controller functions

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

Preface

The release of modern versions of the JavaScript language has made it possible to build more modular and scalable applications in Node.js. Koa is a next-generation Node.js framework that has taken a lot of the newer JavaScript features to make development of robust web applications in Node.js much easier.

You will learn how to efficiently build robust web applications in Koa using modern paradigms and techniques in Node.js development.

Who this book is for

This book is for developers who are interested in building robust and scalable applications using Koa—a modern, expressive, and nimble Node.js framework.

What this book covers

Chapter 1, Introduction to Koa, introduces Koa and talks about its benefits for server-side web development. We will talk about the reasons why developers may choose to use Koa for software development. We will also introduce the remainder of the book and talk about how the book will help its readers to navigate the complex waters of Koa.

Chapter 2, Getting Started with Koa, explains how to get started with server-side development with Koa. We will learn how to install Koa, create a simple server, and build the obligatory Hello World app.

Chapter 3, Koa Core Concepts, discusses the application, context, and request and response objects in Koa. We will also learn about how to create and use middleware. We will go into detail about Koa's philosophy and show readers how the different parts of the framework work.

Chapter 4, Handling Errors in Koa, goes into error handling in Koa. We will look at the different methods of handling errors in Koa. The aim will be to make sure users have a solid foundation and know how to build Koa applications that don't break at slight exceptions.

Chapter 5, Building an API in Koa, dives into building a real-life application in Koa. We will show readers how to create routes, handle requests, and send responses from their APIs.

Chapter 6, Building an Application in Koa, reinforces what we will have learned by building a fully fledged web application in Koa. We will learn how to build a real-life application with authentication and structure it properly in Koa. We will also share some information on further reading to improve on the reader's knowledge of Koa.

To get the most out of this book

To get the most out of this book, having knowledge of JavaScript (ES6 syntax)would be beneficial.

Readers who want to use Koa in tandem with Node.js effectively in order to create fast and real-time backend applications will benefit from this book. 

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

Log in or register at

www.packt.com

.

Select the

SUPPORT

tab.

Click on

Code Downloads & Errata

.

Enter the name of the book in the

Search

box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Server-Side-Development-with-Node.js-and-Koa.js-Quick-Start-Guide. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781789345391_ColorImages.pdf.

Code in action

Visit the following link to check out videos of the code being run:http://bit.ly/2P9N0Fx

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

function logTimeUp() { console.log(“Time up!”);}setTimeout(logTimeUp, 1000);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

dataPromise() .then(data =>

console.log

(`Here is ${data}`));// Here is some important data!

Any command-line input or output is written as follows:

npm install Koa

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Introducing Koa

Node.js, which was introduced in 2009, has become very popular for building applications and APIs on the web. One of the major factors that influenced its increase in popularity is the fact that developers can now use a single language for developing their applications, both on the server side and client side. JavaScript developers who usually only worked on client-side applications in the past could now work on server-side applications with the same development stack. This increase in popularity and adoption has led to a lot of community enthusiasm and support, which by extension has caused a lot of frameworks and plugins being developed to optimize scripting and software development in Node.js.

Many of these frameworks are focused on different ideologies and functionalities. Express.js, with over four million weekly downloads as at the time of writing, is one of the more popular frameworks for Node.js. It was built to be a very simple and unopinionated framework for quickly building out web applications in Node.js. Koa.js was built to be an improvement on Express.js, with the same underlying philosophy.

Since its introduction, JavaScript has continually evolved and every iteration brings with it advantages and upgrades. Koa leverages on a lot of new and shiny things in the newer JavaScript versions, such as the async... await syntax. These features are part of what makes Koa a fast and easy-to-use web development tool.

The topics that will be covered in this chapter are the following:

What is Koa?

What can you do with Koa?

Why choose Koa?

When you should not use Koa

Introducing Koa2

Koa versus Express