Автор: James Smith
Издательство: Leanpub
Год: 2024-02-02
Страниц: 132
Язык: английский
Формат: pdf (true), azw3, mobi, epub
Размер: 10.1 MB
Learn by doing: code a Web server in Node.js.
Most people use HTTP daily, but few understand its inner workings. This "Build Your Own X" book dives deep, teaching basics from scratch for a clearer understanding of the tools and tech we rely on.
The first step is to make programs talk over a network. This is also called socket programming. But socket programming is more than just gluing APIs together! It’s easy to end up with half-working solutions if you skip the basics.
In order to communicate over a network, the data sent over the network must conform to a specific format called a “protocol”. Learn how to create or implement any network protocols by using HTTP as the target.
You probably already know something about HTTP, such as URLs, different methods like GET and POST, response codes, various headers, and etc. But have you ever thought that you can create all the details from scratch, by your own code? It’s not very complicated and it’s rewarding.
Network programming.
Protocols & communication.
HTTP in detail.
WebSocket & concurrency.
The project uses Node.js without any dependencies, but many concepts are language-agnostic, so it’s valuable for learners of any language. Code samples use TypeScript with type annotations for readability, but the differences from JS are minor.
Most Node.js library functions related to IO are either callback-based or promise-based. Promises can be viewed as another way to manage callbacks. These are also described as asynchronous, meaning that the result is delivered via a callback. These APIs do not block the event loop because the JS code doesn’t wait for the result; instead, the JS code returns to the runtime, and when the result is ready, the runtime invokes the callback to continue your program. The opposite is the synchronous API, which blocks the calling OS thread to wait for the result.
Beyond coding exercises
At the end of each chapter, there are discussions аbout:
What’s missing from the code? The gap between toys and the real thing, such as optimizations and applications.
Important concepts beyond coding, such as event loops and backpressure. These are what you are likely to overlook.
Design choices. Why stuff has to work that way? You can learn from both the good ones and the bad ones.
Alternative routes. Where you can deviate from this book.
Build your own X
Why take on a build-your-own-X challenge? A few scenarios to consider
Students: Solidify learning, build portfolio, stand out in future careers.
Developers: Master fundamentals beyond frameworks and tools.
Hobbyists: Explore interests with flexible, extensible projects.
This is part of the “Build Your Own X” book series, which includes books on building your own Redis, database, and compiler.
Скачать Build Your Own Web Server From Scratch In Node.JS : Learn network programming, HTTP, and WebSocket by coding a Web Server