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: Create real-time server-side applications with this practical, step-by-step guide , Third Edition

eBook
€20.98 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Node.js Web Development

Chapter 2. 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, Mac, or Windows
  • How to install the NPM package manager and some popular tools
  • The Node.js module system

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, Mac OS X, and so on), as well as on Microsoft Windows thanks to extensive assistance from Microsoft. 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...

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 Mac OS X with MacPorts

The MacPorts project (http://www.macports.org/) has for years been packaging a long list of open source software packages for Mac OS X, 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:

$ sudo port search nodejs npm
nodejs @4.4.3 (devel, net)
    Evented I/O for V8 JavaScript

nodejs-devel @5.10.0 (devel, net)
    Evented I/O for V8 JavaScript

Found 2 ports.
--
npm @2.15.2 (devel)
    node package manager

npm-devel @3.8.6 (devel)
  ...

Installing from source on POSIX-like systems

Installing the prepackaged Node.js distributions is currently 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 contained within the source distribution at https://github.com/nodejs/node/blob/master/README.md.

Installing prerequisites

As noted in the preceding section, there are three prerequisites...

Installing developer tools on Mac OS X

Developer tools (such as GCC) are an optional installation on Mac OS X. Fortunately, they're easy to acquire.

You start with Xcode, which is available, for free through the Mac App Store. Simply search for Xcode and click on the Get button. Once you have Xcode installed, open a Command Prompt window and type the following:

$ xcnwode-select --install

This installs the Xcode command-line tools.

Installing developer tools on Mac OS X

For additional information, visit http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/.

Installing from source for all POSIX-like systems

First, download the source from http://nodejs.org/download. One way to do this is with your browser and another way is as follows, substituting your preferred version:

$ mkdir src
$ cd src
$ wget https://nodejs.org/dist/v4.2.6/node-v4.2.6.tar.gz
$ tar xvfz node-v4.2.6.tar.gz
$ cd node-v4.2.6

The next step is to configure the source so that it can be built. It is done with the typical sort of configure script and...

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 5.x, and it's expected that everything we'll cover is compatible with Node.js 5.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, and so on) are what they're calling Long Term Support (LTS), while the odd numbered releases (5.x, 7.x, and so on) are where current new feature development occurs. While the development branch is kept stable, the LTS releases are more positioned as being more appropriate for production use.

At the time of writing this, Node.js 4.x is the current LTS release; Node.js 6.x was just released and will eventually become the LTS release. Refer to https://github.com/nodejs/LTS/.

It's likely that everything shown in this book will...

System requirements


Node.js runs on POSIX-like operating systems, various UNIX derivatives (Solaris, for example) or workalikes (Linux, Mac OS X, and so on), as well as on Microsoft Windows thanks to extensive assistance from Microsoft. 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...

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 Mac OS X with MacPorts

The MacPorts project (http://www.macports.org/) has for years been packaging a long list of open source software packages for Mac OS X, 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:

$ sudo port search nodejs npm
nodejs @4.4.3 (devel, net)
    Evented I/O for V8 JavaScript

nodejs-devel @5.10.0 (devel, net)
    Evented I/O for V8 JavaScript

Found 2 ports.
--
npm @2.15.2 (devel)
    node package manager

npm-devel @3.8.6 (devel)
    node...

Installing from source on POSIX-like systems


Installing the prepackaged Node.js distributions is currently 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 contained within the source distribution at https://github.com/nodejs/node/blob/master/README.md.

Installing prerequisites

As noted in the preceding section, there are three prerequisites: a C compiler...

Installing developer tools on Mac OS X


Developer tools (such as GCC) are an optional installation on Mac OS X. Fortunately, they're easy to acquire.

You start with Xcode, which is available, for free through the Mac App Store. Simply search for Xcode and click on the Get button. Once you have Xcode installed, open a Command Prompt window and type the following:

$ xcnwode-select --install

This installs the Xcode command-line tools.

For additional information, visit http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/.

Installing from source for all POSIX-like systems

First, download the source from http://nodejs.org/download. One way to do this is with your browser and another way is as follows, substituting your preferred version:

$ mkdir src
$ cd src
$ wget https://nodejs.org/dist/v4.2.6/node-v4.2.6.tar.gz
$ tar xvfz node-v4.2.6.tar.gz
$ cd node-v4.2.6

The next step is to configure the source so that it can be built. It is done with the typical sort of configure script and you...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn about server-side JavaScript with Node.js and Node modules through the most up-to-date book on Node.js web development
  • Understand website development both with and without the Connect/Express web application framework
  • Develop both HTTP server and client applications

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. Node.js Web Development shows JavaScript is not just for browser-side applications. It can be used for server-side web application development, real-time applications, microservices, and much more. 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 and maintain your own Node.js application. 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 much more.

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 for both development and deployment
  • Use the Express application framework
  • Configure Bootstrap for mobile-first theming
  • Use data storage engines such as MySQL, SQLITE3, and MongoDB
  • Understand user authentication methods, including OAuth, with third-party services
  • Deploy Node.js to live servers, including microservice development with Docker
  • Perform unit testing with Mocha
  • Perform functional testing of the web application with CasperJS

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 27, 2016
Length: 376 pages
Edition : 3rd
Language : English
ISBN-13 : 9781785881503
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 27, 2016
Length: 376 pages
Edition : 3rd
Language : English
ISBN-13 : 9781785881503
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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
€264.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 103.97
Node.js  Design Patterns
€41.99
Node.js Web Development
€36.99
RESTful  Web API Design with Node.js
€24.99
Total 103.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. About Node.js Chevron down icon Chevron up icon
2. Setting up Node.js Chevron down icon Chevron up icon
3. Node.js Modules Chevron down icon Chevron up icon
4. HTTP Servers and Clients – A Web Application's First Steps Chevron down icon Chevron up icon
5. Your First Express Application Chevron down icon Chevron up icon
6. Implementing the Mobile-First Paradigm Chevron down icon Chevron up icon
7. Data Storage and Retrieval Chevron down icon Chevron up icon
8. Multiuser Authentication the Microservice Way Chevron down icon Chevron up icon
9. Dynamic Interaction between Client and Server with Socket.IO Chevron down icon Chevron up icon
10. Deploying Node.js Applications Chevron down icon Chevron up icon
11. Unit Testing Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(18 Ratings)
5 star 66.7%
4 star 5.6%
3 star 5.6%
2 star 16.7%
1 star 5.6%
Filter icon Filter
Top Reviews

Filter reviews by




Huguette Dec 28, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was having a little bit of experiences with Node.js and I was looking a book to really improve my skills. This book is well written and the example are clear and the code well explained. I recommend this book if you are looking for a good introduction to node.js
Amazon Verified review Amazon
Khan Dec 17, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It is intended towards people who are new to NodeJS and want to learn the very basics of it. I managed to finish it in one weekend with other weekend chores. I like the emphasis on basic concept supported by different examples.I read 2 more books after this one on MEAN stack and had I not read this one first, it would be harder to grasp those.
Amazon Verified review Amazon
duffn Jul 05, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is an excellent book covering a wide range of topics surrounding Node.js web development.David does a superb job of leading you through the full lifecycle of a Node.js web application, explaining each piece along the way. You will gain a deep understanding of Node.js development all the way from initial setup to testing and deployment.This is not a book where you are simply told to copy and paste code and that is all. David ensures that you gain a solid competency in each section before moving on to the next. You WILL have excellent knowledge of Node.js web development after reading this book.I would highly recommend this book for Node.js developers both new and old. There is something to be gained for all.Disclaimer: I was the reviewer for this book.
Amazon Verified review Amazon
Luis Henrique Z. Correa Dec 05, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This books exceeds my expectation, very complete and has a very complete demo about this tecnology, I recommend.
Amazon Verified review Amazon
AA Aug 22, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book with amazing attention to detail and exciting projectsToo often code books fall into the classic "copy this, get that" format for teaching code which is useful for short term projects but rarely useful for actual learning. With clear, concise examples that are legitimately interesting as well as step by step instructions for implementation on a wide variety of operating systems this book strikes the perfect balance between showing and telling which allows the reader to understand Node.What I was really impressed with is the emphasis on testing and debugging. For me, learning how to debug and test/build the environment is half the battle of learning a new language. This book has a very in-depth tutorial to setting up an environment and using the debugging and testing tools available. This helps remove a lot of the mystery that comes with new languages, and builds a better foundation for the reader.The book is also very well written and can explain really complex topics in a way that makes it easier to understand and uses code examples and exercises to supplement the text that is already there.Overall, I would highly recommend this book to any developers looking to dive into Node as well as any developers looking to brush up on the newest and latest changes to JavaScript.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.