Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Rufus Stewart

There are plenty of definitions to be found online. Let's take a look at a couple of the more popular ones. This is what the project's home page has to say: - Node.js(R) is a JavaScript runtime built on Chrome's V8 JavaScript engine. And this is what Stack Overflow has to offer: - Node.js is an event-based, non-blocking, asynchronous I/O runtime that uses Google's V8 JavaScript engine and libuv library. Hmmm, "event-based", "non-blocking", "asynchronous I/O" - that's quite a lot to digest in one go. So let's approach this from a different angle and begin by focusing on the other detail that both descriptions mention - the V8 JavaScript engine.Node Is Built on Google Chrome's V8 JavaScript EngineThe V8 engine is the open-source JavaScript engine that runs in Google Chrome and other Chromium-based web browsers, including Brave, Opera, and Vivaldi. It was designed with performance in mind and is responsible for compiling JavaScript directly to native machine code that your computer can execute.However, when we say that Node is built on the V8 engine, we don't mean that Node programs are executed in a browser. They aren't. Rather, the creator of Node (Ryan Dahl) took the V8 engine and enhanced it with various features, such as a file system API, an HTTP library, and a number of operating system-related utility methods.This means that Node.js is a program we can use to execute JavaScript on our computers. In other words, it's a JavaScript runtime. How Do I Install Node.js? In this next section, we'll install Node and write a couple of simple programs. We'll also look at npm, a package manager that comes bundled with Node. Node Binaries vs Version Manager Many websites will recommend that you head to the official Node download page and grab the Node binaries for your system. While that works, I would suggest that you use a version manager instead. This is a program that allows you to install multiple versions of Node and switch between them at will. There are various adva

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on, beginner-friendly guide that takes you from installing Node.js to building a modular web application with an HTTP server, router, and request handlers—perfect for developers with some JavaScript or backend experience who want to understand how Node really works under the hood. 【Book Arc】 - **Opening (~0%–9%)**: Introduces Node.js as a JavaScript runtime built on Chrome's V8 engine, explains why it's different from browser JavaScript, and walks through installation (recommending version managers over binaries), verifying setup with `node -v`, and writing a first "Hello, World!" script. Also covers npm basics, including global package installation and linting with jshint. - **Early (~9%–16%)**: Shifts to mindset—why JavaScript on the server matters and what it means to move from frontend tinkering to backend development. Sets up a concrete project goal (an image upload app) and deliberately adds extra abstraction to teach scalable architecture, breaking the app into an HTTP server, router, and request handlers. - **Early (~16%–28%)**: Builds the first real components: a basic HTTP server in `server.js`, a main entry file `index.js`, and explains how Node modules work with `require` and `exports`. Introduces callbacks by showing how functions can be passed as arguments, and covers parsing URLs with the `url` and `querystring` modules. - **Middle (~28%–38%)**: Connects server, router, and request handlers through dependency injection. Shows how to pass a `handle` object (mapping URL paths to handler functions) into the router, achieving loose coupling. Includes a detour into functional programming concepts, referencing Steve Yegge's "Execution in the Kingdom of Nouns" to explain why verbs (functions) matter over nouns (objects). - **Middle (~38%–47%)**: Demonstrates the critical difference between blocking and non-blocking operations with a live experiment—adding a 10-second `sleep` to one handler blocks all other requests. Explains why callbacks are essential for async operations and why the current synchronous return pattern breaks, setting up the fix: passing the response object through the stack so handlers can respond asynchronously. 【Key Takeaways】 - **Node.js is a server-side JavaScript runtime, not a browser tool** (Opening): Built on V8 but enhanced with file system, HTTP, and OS utilities, it lets you run JavaScript directly on your computer. This is the foundation for everything that follows. - **Use a version manager to install Node** (Opening): Instead of downloading binaries, tools like nvm let you switch between Node versions easily—useful for testing code across different releases and avoiding permission headaches. - **Node supports modern JavaScript (ES6+) out of the box** (Opening): Since you target one runtime (V8), you can write with the latest syntax without worrying about browser compatibility—a major advantage over frontend development. - **Modularity is key to scalable Node apps** (Early): Splitting code into `index.js` (entry point) and `server.js` (HTTP server module) keeps things readable. Using `require` and `exports` turns files into reusable modules, just like built-in ones. - **Callbacks are the heart of Node's async model** (Early): Functions can be passed as arguments and invoked later—this is how `http.createServer(onRequest)` works. Understanding this "function as a value" concept is essential before tackling real async code. - **Dependency injection enables loose coupling** (Middle): Passing a `handle` object (mapping URLs to handler functions) into the router—rather than hardcoding logic—makes the app extensible and mirrors how larger frameworks organize code. - **Blocking operations freeze everything** (Middle): A synchronous `sleep` in one handler delays all other requests, proving why non-blocking I/O matters. The fix involves passing the `response` object through the call stack so handlers can respond when async work completes. 【Reading Tips】 - **Skim the installation and npm sections** (Opening): If you already have Node installed, jump ahead—the key takeaway is just "use a version manager" and "check with `node -v`." - **Deep-read the callback and module explanations** (Early): The examples with `say()` and `execute()` are deceptively simple but crucial. Make sure you truly understand passing functions as arguments before moving on. - **Do the blocking experiment yourself** (Middle): The two-browser-window test with `/start` and `/upload` is the most valuable hands-on moment—it makes the async problem visceral and memorable. - **Watch for translation quirks**: Some code comments and variable names appear in Spanish (e.g., `exports.subir` for upload). Don't let this confuse you—focus on the structure, not the labels. - **Take away the architecture pattern, not just the code**: The server → router → handlers flow with dependency injection is a mini-framework you can reuse in real projects, even if you'd normally use Express. 【Coverage Limits】 Excerpts cover roughly the first half of the book (up to ~47%), focusing on setup, modules, callbacks, routing, and blocking vs. non-blocking. Later sections on actual file uploads, POST handling, and production deployment are not covered in this guide.
Page 7
rks, I would suggest that you use a version manager instead. This is a program that allows you to install multiple versions of Node and switch between them a...
View in text
Page 19
s more or less standard to name your main file as index.js . It also makes sense that we put our server module in a file called server.js .     Let's start w...
View in text
Excerpt 3
o our onRequest () function the logic required to find what URL path the browser requested:   var http = require ("http"); function route (pathname) {   cons...
View in text
Excerpt 4
ing: The URL / start takes 10 seconds to load, as we expect. But the URL / upload also takes 10 seconds to load, although there is no sleep () defined in the...
View in text
Excerpt 5
ound");     response.end (); }   exports.route = route; And in requestHandlers.js , we include the information from our upload handler :   function start (re...
View in text
Excerpt 6
eter (person: string) { return "Hello," + person; } console.log (greeter ("TypeScript"));   Now compilation. We type in the console:   $ tsc hello.ts     The...
View in text
Excerpt 7
ediately immediately after loading the DOM of the document. way, referring to a specific instance of the class. Inheritance is supported by a single class an...
View in text
Excerpt 8
fact, overlap basic needs of working with JSON. JSON.parse () method converts serialized JSON string into a JavaScript object:   var obj = JSON.parse ('{"nam...
View in text
Tags
AI categories
JavaScriptBackendWeb Technology
Publish Year: 2020
Language: English
File Format: PDF
File Size: 557.4 KB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…