Deno Web Development

Book description

Key Features

  • Understand Deno’s essential concepts and features
  • Learn how to use Deno in real-world scenarios
  • Use Deno to develop, test, and deploy web applications and tools

Book Description

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.

What you will learn

  • Understand why you should use Deno
  • Get to grips with tooling and the Deno ecosystem
  • Build Deno web applications using existing Node.js knowledge and the newest ECMA Script 6 features
  • Explore the standard library and the benefits of Deno’s security model
  • Discover common practices and web frameworks to build a REST API in Deno
  • Structure a web application using common architecture practices
  • Test and deploy a Deno application in the cloud using Docker

Who this book is for

This book is for web developers who want to leverage their JavaScript and TypeScript skills in a secure, simple, and modern runtime, using Deno for web app development. Beginner-level knowledge of Node.js is recommended but not required.

Table of contents

  1. Deno Web Development
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Reviews
  7. Section 1: Getting Familiar with Deno
  8. Chapter 1: What is Deno?
    1. A little history
      1. Handling I/O
      2. Node.js enters the scene
    2. Why Deno?
      1. Presenting Deno
      2. A web browser for command-line scripts
    3. Architecture and technologies that support Deno
      1. Inspiration from POSIX systems
      2. Architecture
    4. Grasping Deno's limitations
      1. Not as stable as Node.js
      2. Better HTTP latency but worse throughput
      3. Compatibility with Node.js
      4. TypeScript compiler speed
      5. Lack of plugins/extensions
    5. Exploring use cases
      1. A flexible scripting language
      2. Safer desktop applications
      3. A quick and complete environment to write tools
      4. Running on embedded devices
      5. Generating browser-compatible code
      6. Full-fledged APIs
    6. Summary
  9. Chapter 2: The Toolchain
    1. Technical requirements
    2. Setting up the environment
      1. Installing Deno
    3. Installing VS Code
      1. Shell completions
    4. Hello World
    5. Debugging code in Deno
    6. Modules and third-party dependencies
      1. Locally cached dependencies
      2. Managing dependencies
      3. Import maps
      4. Inspecting modules
    7. Exploring the documentation
    8. Running and installing scripts
      1. Installing utility scripts
    9. Permissions
    10. Using the test command
      1. Filtering tests
      2. Fail fast
    11. Formatting and linting
      1. Formatting
      2. Lint
    12. Bundling code
    13. Compiling to a binary
    14. Using the upgrade command
    15. Summary
  10. Chapter 3: The Runtime and Standard Library
    1. Technical requirements
    2. The Deno runtime
      1. Stability
      2. Program lifecycle
      3. Web APIs
    3. Exploring the Deno namespace
      1. Building a simple ls command
      2. Using dynamic permissions
      3. Using the filesystem APIs
      4. Using buffers
      5. Reading and writing from Deno.Buffer
    4. Using the standard library
      1. Adding colors to our simple ls
    5. Building a web server using the HTTP module
    6. Summary
  11. Section 2: Building an Application
  12. Chapter 4: Building a Web Application
    1. Technical requirements
    2. Structuring a web application
      1. Deno as an unopinionated tool
      2. The most important part of an application
      3. What is our application about?
      4. Understanding folder structure and application architecture
      5. Developing the business logic
      6. Developing the data accessing logic
      7. Creating the web server
      8. Wiring the web server to the business logic
    3. Exploring Deno HTTP frameworks
      1. What alternatives exist?
      2. The verdict
    4. Summary
  13. Chapter 5: Adding Users and Migrating to Oak
    1. Technical requirements
    2. Managing dependencies and lock files
      1. Using a centralized dependency file
      2. Creating a lock file
    3. Writing a web server with Oak
      1. Adding event listeners to an Oak application
      2. Handling routes in an Oak application
      3. Connecting the router to the application
    4. Adding users to the application
      1. Creating the user module
      2. Storing a user in the database
      3. Creating the user repository
      4. Creating the register endpoint
      5. Wiring the user controller with the web layer
    5. Summary
  14. Chapter 6: Adding Authentication and Connecting to the Database
    1. Technical requirements
    2. Using middleware functions
      1. How does middleware work?
      2. Adding request timing via middleware
      3. Adding request logging via middleware
    3. Adding authentication
      1. Creating the login business logic
      2. Creating the login endpoint
    4. Adding authorization with JWT
      1. Returning a token from login
      2. Making an authenticated route
    5. Connecting to MongoDB
      1. Creating a User MongoDB repository
      2. Installing the MongoDB client library
      3. Developing the MongoDB repository
      4. Connecting the application to MongoDB
      5. Connecting to a MongoDB cluster
    6. Summary
  15. Chapter 7: HTTPS, Extracting Configuration, and Deno in the Browser
    1. Technical requirements
    2. Enabling CORS and HTTPS
      1. Enabling CORS
      2. Enabling HTTPS
    3. Extracting configuration and secrets
      1. Creating a configuration file
      2. Accessing secret values
    4. Running Deno code in the browser
    5. Summary
  16. Section 3: Testing and Deploying
  17. Chapter 8: Testing – Unit and Integration
    1. Technical requirements
    2. Writing your first test in Deno
      1. Defining a test
      2. A unit test for MuseumController
    3. Writing an integration test
    4. Testing the web server
    5. Creating integration tests for the application
    6. Testing the application together with the API client
    7. Benchmarking parts of the application
    8. Summary
  18. Chapter 9: Deploying a Deno Application
    1. Technical requirements
    2. Preparing the environment for the application
    3. Creating a Dockerfile for the Deno application
      1. Running a Terminal inside a container
    4. Building and running the application in Heroku
      1. Creating the application in Heroku
      2. Building and running the Docker image
    5. Configuring the application for deployment
      1. Getting the application port from the environment
    6. Summary
  19. Chapter 10: What's Next?
    1. Looking back at our journey
    2. Deno's roadmap
    3. Deno's future and community
      1. Interesting things happening in the community
    4. Publishing a package to Deno's official registry
    5. Summary
    6. Why subscribe?
  20. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think

Product information

  • Title: Deno Web Development
  • Author(s): Alexandre Portela dos Santos
  • Release date: March 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800205666