Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Professional JavaScript
Professional JavaScript

Professional JavaScript: Fast-track your web development career using the powerful features of advanced JavaScript

Arrow left icon
Profile Icon Hugo Di Francesco Profile Icon Philip Kirkbride Profile Icon Vinicius Isola Profile Icon Siyuan Gao
Arrow right icon
$20.98 $29.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Sep 2019 664 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Hugo Di Francesco Profile Icon Philip Kirkbride Profile Icon Vinicius Isola Profile Icon Siyuan Gao
Arrow right icon
$20.98 $29.99
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3 (2 Ratings)
eBook Sep 2019 664 pages 1st Edition
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$20.98 $29.99
Paperback
$43.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Professional JavaScript

2. Node.js and npm

Learning Objectives

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

  • Install and use Node.js to build applications
  • Run JavaScript code using the Node.js execution environment
  • Install and manage multiple Node.js versions using nvm
  • Identify and use modules developed by other developers using npm
  • Create and configure your own npm package

In this chapter, we will switch gears to the backend world by learning about Node.js and the basic concepts around it. We will go through how to install and manage multiple versions of Node.js using nvm, and then we will learn about npm and how to find and use external modules.

Introduction

In the previous chapter, we learned about how HTML becomes the DOM and how to use JavaScript to query and manipulate the content of a page.

Before JavaScript, all pages were static. After Netscape introduced the scripting environment to its browser, developers started using it to create dynamic and responsive applications. The applications started to become more and more complex but the only place where JavaScript was running was inside the browser. Then, in 2009, Ryan Dahl, the original developer of Node.js, decided to create a way to run JavaScript on the server side, simplifying the web developer's life by allowing them to build applications without having to depend on other languages.

In this chapter, you will learn how Node.js works and how to use it to create scripts using JavaScript. You will learn about the basics of the Node.js core APIs, where to find their documentation, and how to use their read-eval-print loop (REPL) command line.

With the skills...

What is Node.js?

Node.js is an execution environment that runs on top of the V8 JavaScript engine. Its base premise is that it is asynchronous and event-driven. This means that all the blocking operations, such as reading data from a file, can be handled in the background while the other parts of the application continue to do their work. When the data has finished loading, an event is emitted and whoever was waiting for the data can now execute and do the work.

From its inception, Node.js was designed to serve as an efficient backend for web applications. Because of that, it was widely adopted by companies of all sizes and industry types. Trello, LinkedIn, PayPal, and NASA are some of the companies that use Node.js in multiple parts of their technology stack.

But what is an execution environment? An execution environment provides basic functionality, such as APIs, for a programmer to write applications. Think about the browser, for example – it has the DOM, objects such...

Node Version Manager (nvm)

Node.js and JavaScript have a huge community and a very fast-paced development cycle. Because of this rapid development and its release cycles, it is very easy to become out of date (check Node.js's previous releases page for more information: https://nodejs.org/en/download/releases/).

Can you imagine working on a project that uses Node.js and is a few years old? By the time you come back to fix a bug, you will notice that the version you have installed can't run the code anymore because of some compatibility issues. Or, you will find that you can't change the code using your current version since what is running in production is a couple of years old and doesn't have async/await or some other lifesaving feature you use a lot in the most recent version.

That issue happens with all programming languages and development environments, but in Node.js, this is prominent because of the extremely fast release cycles.

To solve this, it...

Node Package Manager (npm)

When someone talks about Node Package Manager or npm for short, they can be referring to one or more of the following three things:

  • A command-line application that manages packages for a Node.js application
  • The repository where developers and companies publish their packages for others to use
  • The website where people manage their profile and search for packages

Most programming languages offer at least one way for developers to share packages with each other: Java has Maven, C# has NuGet, Python has PIP, and so on. Node.js started to ship with its own package manager just a few months after its initial release.

Packages can include any type of code that developers think would be useful to others. And sometimes, they also include tools to aid developers in terms of local development.

As the packaged code needs to be shared, there needs to be a repository where all the packages are stored. And to publish their packages, authors...

Summary

In this chapter, we learned about what Node.js is and how its single-threaded, asynchronous, event-driven programming model can be used to build simple and efficient applications. We also learned about nvm and how to manage multiple versions of Node.js. Then, we studied npm and used external libraries in our Node.js applications. Finally, we learned what npm scripts are and some basic concepts related to them.

To help you understand what you learned about in this chapter, you can go to the npm repository, find some projects, and explore their code bases. The best way to learn about npm, Node.js, and the packages and libraries that exist out there is to explore other people's code and see what and how they are building and also what libraries they use.

In the next chapter, we will explore the Node.js APIs and learn how to use them to build a real web scraping application. In future chapters, you will learn how to use npm scripts and packages to improve the quality...

Left arrow icon Right arrow icon

Key benefits

  • Write and deploy full-stack applications efficiently with JavaScript
  • Delve into JavaScript’s multiple programming paradigms
  • Get up to speed with core concepts such as modularity and functional programming to write efficient code

Description

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.

Who is this book for?

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.

What you will learn

  • 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 30, 2019
Length: 664 pages
Edition : 1st
Language : English
ISBN-13 : 9781838822750
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Sep 30, 2019
Length: 664 pages
Edition : 1st
Language : English
ISBN-13 : 9781838822750
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 126.97
Advanced JavaScript
$38.99
Professional JavaScript
$43.99
The JavaScript Workshop
$43.99
Total $ 126.97 Stars icon

Table of Contents

10 Chapters
1. JavaScript, HTML, and the DOM Chevron down icon Chevron up icon
2. Node.js and npm Chevron down icon Chevron up icon
3. Node.js APIs and Web Scraping Chevron down icon Chevron up icon
4. RESTful APIs with Node.js Chevron down icon Chevron up icon
5. Modular JavaScript Chevron down icon Chevron up icon
6. Code Quality Chevron down icon Chevron up icon
7. Advanced JavaScript Chevron down icon Chevron up icon
8. Asynchronous Programming Chevron down icon Chevron up icon
9. Event-Driven Programming and Built-In Modules Chevron down icon Chevron up icon
10. Functional Programming with JavaScript Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 0%
1 star 50%
William Jun 04, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good for someone with experience in programming including Javascript, since it does go into more advanced techniques later in the book, but also great for someone to gain a better understanding of Javascript. It fits the requirements of javascript developers: I wasn't sure which book to start with. Since they are quite different and I'm a pretty experienced Javascript developer I opted to start with this.
Amazon Verified review Amazon
GuitarHero Oct 27, 2022
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Shows the code of each task in snippets and omits the whole code put together. Snippets are from different files as well. You need to refer to the downloaded code to see the whole examples completed. I found this really annoying and an unorganised way of learning. The formatting of the book looks like it was copied and pasted from MS word which doesn’t make for pleasant viewing and I would say (just like packt’s fullstack react projects book) makes for ugly representation. Too bad for me Packt disappoints once again and I should of listened to previous reviewers of packt: JavaScript algorithms book who also said they’re not up to scratch and the code was in separate places. O’Reilly seem to just do it better. Their JavaScript book is miles better and cheaper!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.