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
Node.js Web Development
Node.js Web Development

Node.js Web Development: Server-side development with Node 10 made easy , Fourth Edition

eBook
R$80 R$218.99
Paperback
R$272.99
Subscription
Free Trial
Renews at R$50p/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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Node.js Web Development

Setting up Node.js

Before getting started with using Node.js, you must set up your development environment. In the following chapters, we'll use this for development and for non-production deployment.

In this chapter, we will cover the following topics:

  • How to install Node.js from source and prepackaged binaries on Linux, macOS, or Windows
  • How to install Node Package Manager (NPM) and some popular tools 
  • The Node.js module system
  • Node.js and JavaScript language improvements from the ECMAScript committee

So let's get on with it.

System requirements

Node.js runs on POSIX-like operating systems, various UNIX derivatives (Solaris, for example) or workalikes (Linux, macOS, and so on), as well as on Microsoft Windows. It can run on machines both large and small, including the tiny ARM devices such as the Raspberry Pi microscale embeddable computer for DIY software/hardware projects.

Node.js is now available via package management systems, limiting the need to compile and install from source.

Because many Node.js packages are written in C or C++, you must have a C compiler (such as GCC), Python 2.7 (or later), and the node-gyp package. If you plan to use encryption in your networking code, you will also need the OpenSSL cryptographic library. The modern UNIX derivatives almost certainly come with these, and Node.js's configure script, used when installing from source, will detect their presence. If you...

Installing Node.js using package managers

The preferred method for installing Node.js, now, is to use the versions available in package managers, such as apt-get, or MacPorts. Package managers simplify your life by helping to maintain the current version of the software on your computer, ensuring to update dependent packages as necessary, all by typing a simple command such as apt-get update. Let's go over this first.

Installing on macOS with MacPorts

The MacPorts project (http://www.macports.org/) has for years been packaging a long list of open source software packages for macOS, and they have packaged Node.js. After you have installed MacPorts using the installer on their website, installing Node.js is pretty much...

Installing from source on POSIX-like systems

Installing the prepackaged Node.js distributions is the preferred installation method. However, installing Node.js from source is desirable in a few situations:

  • It can let you optimize the compiler settings as desired
  • It can let you cross-compile, say, for an embedded ARM system
  • You might need to keep multiple Node.js builds for testing
  • You might be working on Node.js itself

Now that you have the high-level view, let's get our hands dirty mucking around in some build scripts. The general process follows the usual configure, make, and make install routine that you may already have performed with other open source software packages. If not, don't worry, we'll guide you through the process.

The official installation instructions are in the README.md contained within the source distribution at https://github.com...

Installing multiple Node.js instances with nvm

Normally, you won't install multiple versions of Node.js and doing so adds complexity to your system. But if you are hacking on Node.js itself, or are testing your software against different Node.js releases, you may want to have multiple Node.js installations. The method to do so is a simple variation on what we've already discussed.

Earlier, while discussing building Node.js from source, we noted that one can install multiple Node.js instances in separate directories. It's only necessary to build from source if you need a customized Node.js build, and most folks will be satisfied with pre-built Node.js binaries. They, too, can be installed into separate directories.

To switch between Node.js versions is simply a matter of changing the PATH variable (on POSIX systems), as follows, using the directory where you installed...

Native code modules and node-gyp

While we won't discuss native code module development in this book, we do need to make sure that they can be built. Some modules in the NPM repository are native code, and they must be compiled with a C or C++ compiler to build the corresponding .node files  (the .node extension is used for binary native-code modules).

The module will often describe itself as a wrapper for some other library. For example, the libxslt and libxmljs modules are wrappers around the C/C++ libraries of the same name. The module includes the C/C++ source code, and when installed, a script is automatically run to do the compilation with node-gyp.

The node-gyp tool is a cross-platform command-line tool written in Node.js for compiling native add-on modules for Node.js. We've mentioned native code modules several...

Node.js versions policy and what to use

We just threw around so many different Node.js version numbers in the previous section that you may have become confused over which version to use. This book is targeting Node.js version 10.x, and it's expected that everything we'll cover is compatible with Node.js 10.x and any subsequent release.

Starting with Node.js 4.x, the Node.js team is following a dual-track approach. The even-numbered releases (4.x, 6.x, 8.x, and so on) are what they're calling Long Term Support (LTS), while the odd-numbered releases (5.x, 7.x, 9.x, and so on) are where current new feature development occurs. While the development branch is kept stable, the LTS releases are positioned as being for production use and will receive updates for several years.

At the time of writing, Node.js 8.x is the current LTS release; Node.js 9.x was just released...

Editors and debuggers

Since Node.js code is JavaScript, any JavaScript-aware editor will be useful. Unlike some other languages that are so complex that an IDE with code completion is a necessity, a simple programming editor is perfectly sufficient for Node.js development.

Two editors are worth calling out because they are written in Node.js: Atom and Microsoft Visual Studio Code. 

Atom (https://atom.io/) bills itself as a hackable editor for the 21st century. It is extendable by writing Node.js modules using the Atom API, and the configuration files are easily editable. In other words, it's hackable in the same way plenty of other editors have been, going back to Emacs, meaning one writes a software module to add capabilities to the editor. The Electron framework was invented in order to build Atom, and Electron is a super easy way to build desktop applications...

System requirements


Node.js runs on POSIX-like operating systems, various UNIX derivatives (Solaris, for example) or workalikes (Linux, macOS, and so on), as well as on Microsoft Windows. It can run on machines both large and small, including the tiny ARM devices such as the Raspberry Pi microscale embeddable computer for DIY software/hardware projects.

Node.js is now available via package management systems, limiting the need to compile and install from source.

Because many Node.js packages are written in C or C++, you must have a C compiler (such as GCC), Python 2.7 (or later), and the node-gyp package. If you plan to use encryption in your networking code, you will also need the OpenSSL cryptographic library. The modern UNIX derivatives almost certainly come with these, and Node.js's configure script, used when installing from source, will detect their presence. If you need to install them, Python is available at http://python.org and OpenSSL is available at http://openssl.org.

Installing Node.js using package managers


The preferred method for installing Node.js, now, is to use the versions available in package managers, such as apt-get, or MacPorts. Package managers simplify your life by helping to maintain the current version of the software on your computer, ensuring to update dependent packages as necessary, all by typing a simple command such as apt-get update. Let's go over this first.

Installing on macOS with MacPorts

The MacPorts project (http://www.macports.org/) has for years been packaging a long list of open source software packages for macOS, and they have packaged Node.js. After you have installed MacPorts using the installer on their website, installing Node.js is pretty much this simple:

$ port search nodejs npm
...
nodejs6 @6.12.0 (devel, net)
Evented I/O for V8 JavaScript

nodejs7 @7.10.1 (devel, net)
Evented I/O for V8 JavaScript

nodejs8 @8.9.1 (devel, net)
Evented I/O for V8 JavaScript

nodejs9 @9.2.0 (devel, net)
Evented I/O for V8 JavaScript...

Installing from source on POSIX-like systems


Installing the prepackaged Node.js distributions is the preferred installation method. However, installing Node.js from source is desirable in a few situations:

  • It can let you optimize the compiler settings as desired
  • It can let you cross-compile, say, for an embedded ARM system
  • You might need to keep multiple Node.js builds for testing
  • You might be working on Node.js itself

Now that you have the high-level view, let's get our hands dirty mucking around in some build scripts. The general process follows the usual configure, make, and make install routine that you may already have performed with other open source software packages. If not, don't worry, we'll guide you through the process.

Note

The official installation instructions are in the README.md contained within the source distribution at https://github.com/nodejs/node/blob/master/README.md.

Installing prerequisites

There are three prerequisites: a C compiler, Python, and the OpenSSL libraries. The...

Installing multiple Node.js instances with nvm


Normally, you won't install multiple versions of Node.js and doing so adds complexity to your system. But if you are hacking on Node.js itself, or are testing your software against different Node.js releases, you may want to have multiple Node.js installations. The method to do so is a simple variation on what we've already discussed.

Earlier, while discussing building Node.js from source, we noted that one can install multiple Node.js instances in separate directories. It's only necessary to build from source if you need a customized Node.js build, and most folks will be satisfied with pre-built Node.js binaries. They, too, can be installed into separate directories.

To switch between Node.js versions is simply a matter of changing the PATH variable (on POSIX systems), as follows, using the directory where you installed Node.js:

$ export PATH=/usr/local/node/VERSION-NUMBER/bin:${PATH} 

It starts to be a little tedious to maintain this after a while...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Learn server-side JavaScript coding through the most up-to-date book on Node.js
  • • Explore the latest JavaScript features, and EcmaScript modules
  • • Walk through different stages of developing robust applications using Node.js 10

Description

Node.js is a server-side JavaScript platform using an event-driven, non-blocking I/O model allowing users to build fast and scalable data-intensive applications running in real time. This book gives you an excellent starting point, bringing you straight to the heart of developing web applications with Node.js. You will progress from a rudimentary knowledge of JavaScript and server-side development to being able to create, maintain, deploy and test your own Node.js application.You will understand the importance of transitioning to functions that return Promise objects, and the difference between fs, fs/promises and fs-extra. With this book you'll learn how to use the HTTP Server and Client objects, data storage with both SQL and MongoDB databases, real-time applications with Socket.IO, mobile-first theming with Bootstrap, microservice deployment with Docker, authenticating against third-party services using OAuth, and use some well known tools to beef up security of Express 4.16 applications.

Who is this book for?

This book is for anybody looking for an alternative to the "P" languages (Perl, PHP, and Python), or anyone looking for a new paradigm of server-side application development. You should have at least a rudimentary understanding of JavaScript and web application development.

What you will learn

  • • Install and use Node.js 10 for both development and deployment
  • • Use the Express 4.16 application framework
  • • Work with REST service development using the Restify framework
  • • Use data storage engines such as MySQL, SQLITE3, and MongoDB
  • • Use User authentication methods with OAuth2
  • • Perform Real-time communication with the front-end using Socket.IO
  • • Implement Docker microservices in development, testing and deployment
  • • Perform unit testing with Mocha 5.x, and functional testing with Puppeteer 1.1.x
  • • Work with HTTPS using Let's Encrypt, and application security with Helmet

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 30, 2018
Length: 492 pages
Edition : 4th
Language : English
ISBN-13 : 9781788627368
Vendor :
Google
Languages :
Tools :

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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 30, 2018
Length: 492 pages
Edition : 4th
Language : English
ISBN-13 : 9781788627368
Vendor :
Google
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 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
R$500 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 R$25 each
Feature tick icon Exclusive print discounts
R$800 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 R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 702.97
Node.js Web Development
R$272.99
RESTful Web API Design with Node.js 10, Third Edition
R$183.99
Advanced Node.js Development
R$245.99
Total R$ 702.97 Stars icon
Banner background image

Table of Contents

13 Chapters
About Node.js Chevron down icon Chevron up icon
Setting up Node.js Chevron down icon Chevron up icon
Node.js Modules Chevron down icon Chevron up icon
HTTP Servers and Clients Chevron down icon Chevron up icon
Your First Express Application Chevron down icon Chevron up icon
Implementing the Mobile-First Paradigm Chevron down icon Chevron up icon
Data Storage and Retrieval Chevron down icon Chevron up icon
Multiuser Authentication the Microservice Way Chevron down icon Chevron up icon
Dynamic Client/Server Interaction with Socket.IO Chevron down icon Chevron up icon
Deploying Node.js Applications Chevron down icon Chevron up icon
Unit Testing and Functional Testing Chevron down icon Chevron up icon
Security Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(9 Ratings)
5 star 55.6%
4 star 11.1%
3 star 0%
2 star 22.2%
1 star 11.1%
Filter icon Filter
Top Reviews

Filter reviews by




gabriele cossu Aug 15, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
La struttura è molto lineare e vengono toccati tutti gli aspetti salienti del sistema. Ottimo il racconto dell'evoluzione del sistema di pari passo con le versioni di Javascript. Ottima la trattazione di npm. E' descritto il corretto approccio alla programmazione asincrona in cui molti esempi dimostrano differenti approcci ed i trabocchetti in cui si rischia di incappare.Io sviluppo su Node.js da diverso tempo ed ho trovato questo libro molto utile per approfondire aspetti che avevo analizzato superficialmente. Lo consiglio.
Amazon Verified review Amazon
yishai Jan 31, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the first book I read on node, and it was a great experience. The author clearly did a good job. Specially enjoyed the analysis of the Fibonacci sequence case as a demonstration of the unique coding style node calls for. The main perk is that as of the time of writing (January 2019) it is the most updated book available, as far as I know.
Amazon Verified review Amazon
C Bustos Nov 25, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm only through Chapter 7 of this book, but already I can tell that this approach is absolutely the one I will use on any future web applications that I create. In fact, it makes things seem so much easier than other stacks, that I can probably create more applications in less time. I really appreciate how the author (David Herron) takes the more disciplined approaches and highlights how these better habits create more maintainable applications down the road. An example of this is creating an application that can handle different data storage mechanisms so that you can freely switch between them. This is relevant because in a production environment, it is possible that in the future your company wants to change database vendors. This will be a manageable change if you use this approach.Another plus to exploring the different database systems is that some people are more comfortable staying away from complex SQL storage, and this book has a solution for those people. But there are also some environments that demand more relational databases and the ability to query efficiently, and this book addresses both needs.I haven't read the chapters on Security or Multiuser Authentication yet, but it seems these topics aren't easy to find in the wild of the internet or in other tutorial based resources I've encountered, or even in other Node.js books I've read.I have a few years of full stack development using different, outdated stacks than Node.js, so I can't tell if this book is the BEST way to start out in Node for beginners. But if you are wanting to build websites, than I would suggest going straight to this book because it introduces all the relevant technologies that you will need. One of the hardest parts with getting started in web development is learning what all the names of frameworks/libraries mean.For recommendations about using this book, some of these examples I did on Ubuntu Linux and some I did on Windows. I recommend either a Mac or Linux system if you are a beginner. I had trouble with using the Windows system when the code switched to using the ES6 syntax and you needed a work around to get the __dirname variable set. On Windows this resulted in the string being set like '/C:/Users...', so I used a substring to get rid of the first character and that worked. I had other troubles with installing level and sqlite3, but was lazy and just switched to Ubuntu rather than worked the issue out, so it may just require extra work. If you have Ubuntu, use this to work out all the examples.I did find a few errors here and there, but percentage-wise it is relatively low. The quality of the experience and convenience of having so many technologies and web development concerns addressed in the same book outweighs the negative aspect of having to deal with a few errors.Overall, I really enjoyed this book!
Amazon Verified review Amazon
Jay Mar 30, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have this habit where, when I have to learn something new, I prefer a textbook.An experienced developer always has this viewpoint and experience about his work. I need that insight. Further, we get to know the essential stuff with tips and usage advice. Further, all the information is in one single place.This book meets that demand. If your style is like mine, then, sure, this book is a good starting point. Note that, this book won't make you an expert. However, once I was done with the book, I had all the essential I need to develop and deploy node js application. To that extent it is a good book.However, the book has plenty of problems. The code is not laid out properly (I would have liked slightly better indentation). also, some of the code is missing some obvious things, so a little big of searching on internet is required. Also, the book does not talk about debugging at all. Thats...crazy! So, there are some big holes.Still, I give it a five star as the asking price is on the lower side. Decent book for a low price.
Amazon Verified review Amazon
Angel Martínez Oct 13, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Libro bastante completo, con prácticas bien diseñadas y pedagógicas. Lástima que no hay una versión en español, realmente de los libros y temas buenos nunca hay una versión española. Lo nuestro es la fiesta, la cocina, etc..Libro que hay que tener, leer y practicar. Muy bueno.
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.