Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Node.js for Beginners

You're reading from   Node.js for Beginners A comprehensive guide to building efficient, full-featured web applications with Node.js

Arrow left icon
Product type Paperback
Published in May 2024
Publisher Packt
ISBN-13 9781803245171
Length 382 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Ulises Gascón Ulises Gascón
Author Profile Icon Ulises Gascón
Ulises Gascón
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Preface 1. Part 1: Node.js Overview and JavaScript Language
2. Chapter 1: Introduction to Node.js FREE CHAPTER 3. Chapter 2: Setting Up the Development Environment 4. Chapter 3: JavaScript Fundamentals 5. Chapter 4: Asynchronous Programming 6. Part 2: Node.js Ecosystem and Architecture
7. Chapter 5: Node.js Core Libraries 8. Chapter 6: External Modules and npm 9. Chapter 7: Event-Driven Architecture 10. Chapter 8: Testing in Node.js 11. Part 3: Web Application Fundamentals
12. Chapter 9: Handling HTTP and REST APIs 13. Chapter 10: Building Web Applications with Express 14. Part 4: Building Solid Web Applications with Node.js
15. Chapter 11: Building a Web Application Project from Scratch 16. Chapter 12: Data Persistence with MongoDB 17. Chapter 13: User Authentication and Authorization with Passport.js 18. Chapter 14: Error Handling in Node.js 19. Chapter 15: Securing Web Applications 20. Part 5: Mastering Node.js Deployment and Portability
21. Chapter 16: Deploying Node.js Applications 22. Chapter 17: Dockerizing a Node.js Application 23. Index 24. Other Books You May Enjoy

Interacting with JavaScript using Chrome DevTools

There is a set of utilities included in the Chrome browser (https://developer.chrome.com/docs/devtools/overview/) defined as follows:

“Chrome DevTools is a set of web developer tools built directly into the Google Chrome browser. DevTools can help you edit pages on-the-fly and diagnose problems quickly, which ultimately helps you build better websites, faster.”

All Chrome-based browsers have Chrome DevTools, so you can use it with any browser based on Chromium, such as Google Chrome, Microsoft Edge, Brave, and so on.

The Node.js REPL is very useful, but in order to build web applications with Node.js, we can use Chrome DevTools for debug purposes. This debugging will be limited to client-side JavaScript as the Node.js code is not executed directly in the browser.

Chrome DevTools is a very complete tool, so this can be quite overwhelming at first, but we will focus on the most important features for this book: the Console and Network panels.

The Console panel

The Console panel is the primary way to interact with the JavaScript on the website. The console is interactive so we can write JavaScript code and it will be executed immediately; we can also read the console output.

The following video provides a great overview of the tool: https://www.youtube.com/watch?v=76U0gtuV9AY.

You can read the official documentation here: https://developer.chrome.com/docs/devtools/console/.

The Network panel

The Network panel is very powerful. It allows us to inspect HTTP requests and responses so we can see the headers, body, status code, and so on. This will be very useful when we need to debug any kind of web application. You can find a great tutorial at https://www.youtube.com/watch?v=e1gAyQuIFQo.

You can read the official documentation here: https://developer.chrome.com/docs/devtools/network/.

Using Chrome DevTools

In our case, we will start from an empty website. We will use the Console panel to write JavaScript code that will change the page, and then we will inspect the HTTP requests. Follow these steps:

  1. In your browser, go to about:blank; by default, this will show a blank page.
  2. Open DevTools by right-clicking on the page and clicking Inspect.
  3. Go to the Console tab and type document.body.innerHTML = '<h1>Hello World!</h1>' and press Enter.
Figure 2.1 – Web browser screenshot

Figure 2.1 – Web browser screenshot

  1. Now, you should see the Hello World! text on the page.
Figure 2.2 – Web browser screenshot with Hello World! text

Figure 2.2 – Web browser screenshot with Hello World! text

  1. Go to the Network tab and navigate to https://packt.com. You should see a lot of activity.
Figure 2.3 – Web browser activity

Figure 2.3 – Web browser activity

This was a simple example for you to get familiar with the Chrome DevTools, but you can do much more with it. I recommend you read the official documentation to learn more.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image