Deno Web Development - Alexandre Portela dos Santos - E-Book

Deno Web Development E-Book

Alexandre Portela dos Santos

0,0
27,59 €

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

Mehr erfahren.
Beschreibung

Deno is a JavaScript and TypeScript runtime with secure defaults and a great developer experience. With Deno Web Development, you'll learn all about Deno's primitives, its principles, and how you can use them to build real-world applications. The book is divided into three main sections: an introduction to Deno, building an API from scratch, and testing and deploying a Deno application.
The book starts by getting you up to speed with Deno's runtime and the reason why it was developed. You'll explore some of the concepts introduced by Node, why many of them transitioned into Deno, and why new features were introduced. After understanding Deno and why it was created, you will start to experiment with Deno, exploring the toolchain and writing simple scripts and CLI applications. As you progress to the second section, you will create a simple web application and then add more features to it. This application will evolve from a simple 'hello world' API to a web application connected to the database, with users, authentication, and a JavaScript client. In the third section, the book will take you through topics such as dependency management, configuration and testing, finishing with an application deployed in a cloud environment.
By the end of this web development book, you will become comfortable with using Deno to create, maintain, and deploy secure and reliable web applications.

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

EPUB
MOBI

Seitenzahl: 350

Veröffentlichungsjahr: 2021

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.



Deno Web Development

Write, test, maintain, and deploy JavaScript and TypeScript web applications using Deno

Alexandre Portela dos Santos

BIRMINGHAM—MUMBAI

Deno Web Development

Copyright © 2021 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.

Associate Group Product Manager: Pavan Ramchandani

Publishing Product Manager: Aaron Tanna

Commissioning Editor: Pavan Ramchandani

Senior Editor: Sofi Rogers

Content Development Editor: Rakhi Patel

Technical Editor: Saurabh Kadave

Copy Editor: Safis Editing

Project Coordinator: Manthan Patel

Proofreader: Safis Editing

Indexer: Rekha Nair

Production Designer: Prashant Ghare

First published: March 2021

Production reference: 1240321

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80020-566-6

www.packt.com

To my parents, Fátima and António, and to my brother Pedro. Thanks for your unconditional support – you are the best. Wouldn't have made it without you.

To my friends, who helped me make this book a reality. Thank you, Felipe, Gonçalo, Bruno, Nuno, János, João, and Miguel for all the conversations, reviews, and suggestions. 

– Alexandre

Foreword

Many of us witnessed a time where JavaScript was not considered a real language but rather a scripting tool for those who wanted to improve the user experience when interacting with the browser.

Its increasing popularity drove the JavaScript community to broaden its purpose. Suddenly, someone who was mainly skilled in client-side web development now had the chance to dive into the world of server-side with no language barrier. On top of that, they had something quite natural that was becoming trendy – concurrency and event-driven design.

At the same time, looking around the programming language landscape over the last 10-15 years, other languages were being released as well, positioned to be more advanced alternatives leveraging the learnings of the traditional ones; simpler to package; removing legacy; providing more advanced standard libraries and features so that we developers could focus on delivering value to the end users of the software. There are, however, two trends worth highlighting. Concurrency and interoperability were topics we could see being addressed in all of them. Golang, Kotlin, Elixir, and Rust offered easier ways to handle concurrency, but they also provided an easy way to interop with other languages. You could use Erlang code in Elixir, Java code in Kotlin, C in Golang and Rust, and so on... Interop was critical for language adoption in existing legacy systems.

On one hand, most of these languages did well in solving a problem that Node.js was also solving while being quite mature because they leveraged existing ecosystems with interop capabilities. On the other hand, Node.js suffers from some design decisions that drag improvement in different areas such as security, packaging, and interoperability to name a few. One might say there's some catching up to be done...

Being a software engineer means being in an infinite loop of learning. This book is a remarkable achievement and a must-read in one iteration of that learning loop. It is an introduction to a new language that promises to fill some gaps, building a strong foundation to consolidate the reason why the most popular language in the world is even more everywhere – Deno Web Development: Write, test, maintain, and deploy JavaScript and TypeScript web applications using Deno.

Miguel Loureiro

Chief Technology Officer, KI group

Contributors

About the author

Alexandre Portela dos Santos is a software engineer passionate about products and start-ups. For the last 8+ years, he's been working together with multiple companies, using technology as an enabler for ideas and businesses. With a big interest in education and getting people excited about technology, he makes sure he's always involved with people that are learning about it, be it via blog posts, books, open source contributions, or meetups. This is, by itself, a learning adventure that Alexandre loves to be a part of. Being a true believer that great software only happens through collaboration, ownership, and teams of great people, he strives to nurture those values in every project he works on.

About the reviewers

Maxim Mazurok is a software engineer with a focus on web development. He has 6+ years of enterprise experience in software product and e-commerce companies located in Silicon Valley, Ukraine, and Sydney.

He has applied this experience to teach teens the basics of web development and taught adults more advanced web technologies.

He is passionate about open source and sharing knowledge, an active GitHub contributor, and a Stack Overflow member, always happy to connect.

When not at the computer, he rides a bicycle, takes pictures of nature, and attends meetups and conferences.

Yusuke Tanaka is a software engineer living in Tokyo, Japan. After getting a BS degree in engineering at the University of Tokyo in 2019, he now works at STADIUM Co., Ltd. engaging in the development of a web application that provides an online job interview system. Although he uses TypeScript and Go at work, he has been enthusiastic about the Rust programming language for about 2 years and makes contributions to open source software related to Rust in his spare time. In particular, he is so interested in Deno and the core of Rust that he devotes a lot of time to them. To get in touch with him or for more details, feel free to visit his GitHub (@magurotuna) or Twitter (@yusuktan).

Acknowledgement

Firstly, I am grateful to the editors and publishers who gave me a chance to participate in such a wonderful project. And most of all, I would like to thank Alexandre Santos for making this book happen. I am delighted to get involved in this book, hoping it will help more people recognize the fantastic development experience with Deno.

Table of Contents

Preface

Section 1: Getting Familiar with Deno

Chapter 1: What is Deno?

A little history

Handling I/O

Node.js enters the scene

Why Deno?

Presenting Deno

A web browser for command-line scripts

Architecture and technologies that support Deno

Inspiration from POSIX systems

Architecture

Grasping Deno's limitations

Not as stable as Node.js

Better HTTP latency but worse throughput

Compatibility with Node.js

TypeScript compiler speed

Lack of plugins/extensions

Exploring use cases

A flexible scripting language

Safer desktop applications

A quick and complete environment to write tools

Running on embedded devices

Generating browser-compatible code

Full-fledged APIs

Summary

Chapter 2: The Toolchain

Technical requirements

Setting up the environment

Installing Deno

Installing VS Code

Shell completions

Hello World

Debugging code in Deno

Modules and third-party dependencies

Locally cached dependencies

Managing dependencies

Import maps

Inspecting modules

Exploring the documentation

Running and installing scripts

Installing utility scripts

Permissions

Using the test command

Filtering tests

Fail fast

Formatting and linting

Formatting

Lint

Bundling code

Compiling to a binary

Using the upgrade command

Summary

Chapter 3: The Runtime and Standard Library

Technical requirements

The Deno runtime

Stability

Program lifecycle

Web APIs

Exploring the Deno namespace

Building a simple ls command

Using dynamic permissions

Using the filesystem APIs

Using buffers

Reading and writing from Deno.Buffer

Using the standard library

Adding colors to our simple ls

Building a web server using the HTTP module

Summary

Section 2: Building an Application

Chapter 4: Building a Web Application

Technical requirements

Structuring a web application

Deno as an unopinionated tool

The most important part of an application

What is our application about?

Understanding folder structure and application architecture

Developing the business logic

Developing the data accessing logic

Creating the web server

Wiring the web server to the business logic

Exploring Deno HTTP frameworks

What alternatives exist?

The verdict

Summary

Chapter 5: Adding Users and Migrating to Oak

Technical requirements

Managing dependencies and lock files

Using a centralized dependency file

Creating a lock file

Writing a web server with Oak

Adding event listeners to an Oak application

Handling routes in an Oak application

Connecting the router to the application

Adding users to the application

Creating the user module

Storing a user in the database

Creating the user repository

Creating the register endpoint

Wiring the user controller with the web layer

Summary

Chapter 6: Adding Authentication and Connecting to the Database

Technical requirements

Using middleware functions

How does middleware work?

Adding request timing via middleware

Adding request logging via middleware

Adding authentication

Creating the login business logic

Creating the login endpoint

Adding authorization with JWT

Returning a token from login

Making an authenticated route

Connecting to MongoDB

Creating a User MongoDB repository

Installing the MongoDB client library

Developing the MongoDB repository

Connecting the application to MongoDB

Connecting to a MongoDB cluster

Summary

Chapter 7: HTTPS, Extracting Configuration, and Deno in the Browser

Technical requirements

Enabling CORS and HTTPS

Enabling CORS

Enabling HTTPS

Extracting configuration and secrets

Creating a configuration file

Accessing secret values

Running Deno code in the browser

Summary

Section 3: Testing and Deploying

Chapter 8: Testing – Unit and Integration

Technical requirements

Writing your first test in Deno

Defining a test

A unit test for MuseumController

Writing an integration test

Testing the web server

Creating integration tests for the application

Testing the application together with the API client

Benchmarking parts of the application

Summary

Chapter 9: Deploying a Deno Application

Technical requirements

Preparing the environment for the application

Creating a Dockerfile for the Deno application

Running a Terminal inside a container

Building and running the application in Heroku

Creating the application in Heroku

Building and running the Docker image

Configuring the application for deployment

Getting the application port from the environment

Summary

Chapter 10: What's Next?

Looking back at our journey

Deno's roadmap

Deno's future and community

Interesting things happening in the community

Publishing a package to Deno's official registry

Summary

Why subscribe?

Other Books You May Enjoy

Section 1: Getting Familiar with Deno

In this section, you will get to know what Deno is, why it was created, and how it was created. This section will help you set up the environment and get familiar with the ecosystem and available tooling.

This section contains the following chapters:

Chapter 1, What Is Deno?Chapter 2, The ToolchainChapter 3, The Runtime and Standard Library