Book Image

Professional JavaScript

By : Hugo Di Francesco, Siyuan Gao, Vinicius Isola, Philip Kirkbride
Book Image

Professional JavaScript

By: Hugo Di Francesco, Siyuan Gao, Vinicius Isola, Philip Kirkbride

Overview of this book

In depth knowledge of JavaScript makes it easier to learn a variety of other frameworks, including React, Angular, and related tools and libraries. This book is designed to help you cover the core JavaScript concepts you need to build modern applications. You'll start by learning how to represent an HTML document in the Document Object Model (DOM). Then, you'll combine your knowledge of the DOM and Node.js to create a web scraper for practical situations. As you read through further lessons, you'll create a Node.js-based RESTful API using the Express library for Node.js. You'll also understand how modular designs can be used for better reusability and collaboration with multiple developers on a single project. Later lessons will guide you through building unit tests, which ensure that the core functionality of your program is not affected over time. The book will also demonstrate how constructors, async/await, and events can load your applications quickly and efficiently. Finally, you'll gain useful insights into functional programming concepts such as immutability, pure functions, and higher-order functions. By the end of this book, you'll have the skills you need to tackle any real-world JavaScript development problem using a modern JavaScript approach, both for the client and server sides.
Table of Contents (12 chapters)

About the Book

In depth knowledge of JavaScript makes it easier to learn a variety of other frameworks, including React, Angular, and related tools and libraries. This book is designed to help you cover the core JavaScript concepts you need to build modern applications.

You'll start by learning how to represent an HTML document in the Document Object Model (DOM). Then, you'll combine your knowledge of the DOM and Node.js to create a web scraper for practical situations. As you read through further chapters, you'll create a Node.js-based RESTful API using the Express library for Node.js. You'll also understand how modular designs can be used for better reusability and collaboration with multiple developers on a single project. Later chapters will guide you through building unit tests, which ensure that the core functionality of your program is not affected over time. The book will also demonstrate how constructors, async/await, and events can load your applications quickly and efficiently. Finally, you'll gain useful insights into functional programming concepts such as immutability, pure functions, and higher-order functions.

By the end of this book, you'll have the skills you need to tackle any real-world JavaScript development problem using a modern JavaScript approach, both for the client and server sides.

About the Authors

Hugo Di Francesco is a software engineer who has worked extensively with JavaScript. He holds a MEng degree in mathematical computation from University College London (UCL). He has used JavaScript across the stack to create scalable and performant platforms at companies such as Canon and Elsevier. He is currently tackling problems in the retail operations space with Node.js, React, and Kubernetes while running the eponymous Code with Hugo website. Outside of work, he is an international fencer, in the pursuit of which he trains and competes across the globe.

Siyuan Gao is a software engineer at Electronic Arts. He has a bachelor's degree in computer science from Purdue University. He has worked with JavaScript and Node.js for over 4 years, mainly building efficient backend solutions for high-availability systems. He is also a contributor to the Node.js Core project and has had many npm modules published. In his spare time, he enjoys learning about video game design and machine learning.

Vinicius Isola started programming back in 1999 using Macromedia Flash and ActionScript. In 2005, he took the Java Certification and specialized in building web and enterprise applications. Always working on all parts of the stack, JavaScript and web technologies have always been present in his many job roles and the companies he has worked for. In his free time, he likes to work on open-source projects and mentor new developers.

Philip Kirkbride has over 5 years of experience with JavaScript and is based in Montreal. He graduated from a technical college in 2011 and since then he has been working with web technologies in various roles. He worked with 2Klic, an IoT company contracted by the major electrical heating company Convectair to create smart heaters powered by Z-Wave technology. His role consisted of writing microservices in Node.js and Bash. He has also had a chance to make some contributions to the open-source projects SteemIt (a blockchain-based blogging platform) and DuckDuckGo (a privacy-based search engine).

Learning Objectives

By the end of this book, you will be able to:

  • Apply the core concepts of functional programming
  • Build a Node.js project that uses the Express.js library to host an API
  • Create unit tests for a Node.js project to validate it
  • Use the Cheerio library with Node.js to create a basic web scraper
  • Develop a React interface to build processing flows
  • Use callbacks as a basic way to bring control back

Audience

If you want to advance from being a frontend developer to a full-stack developer and learn how Node.js can be used for hosting full-stack applications, this is an ideal book for you. After reading this book, you'll be able to write better JavaScript code and learn about the latest trends in the language. To easily grasp the concepts explained here, you should know the basic syntax of JavaScript and should've worked with popular frontend libraries such as jQuery. You should have also used JavaScript with HTML and CSS but not necessarily Node.js.

Approach

Each section of this book has been explicitly designed to engage and stimulate you so that you can retain and apply what you learn in a practical context with maximum impact. You'll learn how to tackle intellectually stimulating programming challenges that will prepare you for real-world topics through functional programming and test-driven development practices. Each chapter has been explicitly designed to build upon JavaScript as a core language.

Hardware Requirements

For the optimal experience, we recommend the following hardware configuration:

  • Processor: Intel Core i5 or equivalent
  • Memory: 4 GB of RAM
  • Storage: 5 GB of available space

Software Requirements

We also recommend that you have the following software installed in advance:

Conventions

Code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows:

"The ES6 import function also allows you to import a subsection of a module, rather than importing the whole thing. This is one capability ES6's import has over the Node.js require function. SUSE"

A block of code is set as follows:

let myString = "hello";
console.log(myString.toUpperCase()); // returns HELLO
console.log(myString.length); // returns 5

Installation and Setup

Before we can do awesome things with data, we need to be prepared with the most productive environment. In this short section, we will see how to do that.

Installing Node.js and npm

Installations of Node.js come with npm (Node.js's default package manager) included.

Installing Node.js on Windows:

  1. Find your desired version of Node.js on the official installation page at https://nodejs.org/en/download/current/.
  2. Ensure you select Node.js 12 (the current version).
  3. Ensure that you install the correct architecture for your computer system; that is, either 32-bit or 64-bit. You can find out this information in the System Properties window of your OS.
  4. After you download the installer, simply double-click on the file and follow the user-friendly prompts on-screen.

Installing Node.js and npm on Linux:

To install Node.js on Linux, you have a few good options:

Installing Node.js and npm on macOS:

Similar to Linux, you have a couple of methods for installing Node.js and npm on a Mac. To install Node.js and npm on macOS X, do the following:

  1. Open Terminal for Mac by pressing cmd + Spacebar, typing terminal in the open search box, and hitting Enter.
  2. Install Xcode through the command line by running xcode-select --install.
  3. The easiest way to install Node.js and npm is using Homebrew, which is installed through the command line by running ruby -e "$(curl -fsSL (https://raw.githubusercontent.com/Homebrew/install/master/install).
  4. The final step is to install Node.js and npm. On the command line, run brew install node.
  5. Again, you can also install Node.js and npm via the installer available at https://nodejs.org/en/download/current/.

Installing Git

To install git go to https://git-scm.com/downloads and follow instructions specific to your platform.

Additional Resources

The code bundle for this book is also hosted on GitHub at https://github.com/TrainingByPackt/Professional-JavaScript. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!