- Node.js Web Development
- David Herron
- 475字
- 2021-06-11 18:48:19
HTTP Servers and Clients
Now that you've learned about Node.js modules, it's time to put this knowledge to use by building a simple Node.js web application. The goal of this book is to learn about web application development with Node.js. The next step in that journey is getting a basic understanding of the HTTPServer and HTTPClient objects. To do that, we'll create a simple application that will enable us to explore a popular application framework for Node.js—Express. In later chapters, we'll do more complex work on the application, but before we can walk, we must learn to crawl.
The goal of this chapter is to start to understand how to create applications on the Node.js platform. We'll create a handful of small applications, which means we'll be writing code and talking about what it does. Beyond learning about some specific technologies, we want to get comfortable with the process of initializing a work directory, creating the Node.js code for an application, installing dependencies required by the application, and running/testing the application.
The Node.js runtime includes objects such as EventEmitter, HTTPServer, and HTTPClient, which provide a foundation on which we can build applications. Even if we rarely use these objects directly, it is useful to understand how they work, and in this chapter, we will cover a couple of exercises using these specific objects.
We'll first build a simple application directly using the HTTPServer object. Then, we'll move on to using Express to create an application for computing Fibonacci numbers. Because this can be computationally expensive, we'll use this to explore why it's important to not block the event queue in Node.js and what happens to applications that do. This will give us an excuse to develop a simple background Representational State Transfer (REST) server, an HTTP client for making requests on that server, and the implementation of a multi-tier web application.
In today's world, the microservice application architecture implements background REST servers, which is what we'll do in this chapter.
We will cover the following topics in this chapter:
- Sending and receiving events using the EventEmitter pattern
- Understanding an HTTP server application by building a simple application
- Web application frameworks
- Using the Express framework to build a simple application
- Handling computationally intensive calculations in an Express application and the Node.js event loop
- Making HTTP Client requests
- Creating a simple REST service with Express
By going through these topics, you'll gain an understanding of several aspects of designing HTTP-based web services. The goal is for you to understand how to create or consume an HTTP service and to get an introduction to the Express framework. By the end of this chapter, you'll have a basic understanding of these two tools.
That's a lot to cover, and it will give us a good foundation for the rest of this book.
- Implementing Modern DevOps
- Building a Home Security System with Raspberry Pi
- Twilio Best Practices
- 跟小海龜學Python
- TypeScript圖形渲染實戰:基于WebGL的3D架構與實現
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- INSTANT Passbook App Development for iOS How-to
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Python+Tableau數據可視化之美
- 計算機應用基礎項目化教程
- Drupal 8 Development:Beginner's Guide(Second Edition)
- Lync Server Cookbook
- C++標準庫(第2版)
- 深入解析Java虛擬機HotSpot