Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Node Web Development - Second Edition
Node Web Development - Second Edition

Node Web Development - Second Edition: JavaScript is no longer just for browsers and this exciting introduction to Node.js will show you how to build data-intensive applications that run in real time. Benefit from an easy, step-by-step approach that really works.

eBook
€25.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.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
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Node Web Development - Second Edition

Chapter 2. Setting up Node

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

In this chapter we will:

  • See how to install Node from source and prepackaged binaries on Linux, Mac, or Windows

  • See how to install the npm package manager, and some popular tools

  • Learn a bit about the Node module system

So let's get on with it.

System requirements


Node runs on POSIX-like operating systems, the various UNIX derivatives (Solaris, and so on), or workalikes (Linux, Mac OS X, and so on), as well as on Microsoft Windows, thanks to the extensive assistance from Microsoft. Indeed, many of the Node built-in functions are direct corollaries to POSIX system calls. 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 is now available via package management systems, limiting the need to compile and install from source.

Installing from source requires having a C compiler (such as GCC), and Python 2.7 (or later). 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's configure script (see later when we download and configure the source) will detect their presence. If you should have to...

Installing Node using package managers


The preferred method for installing Node, 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 and 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. After you have installed MacPorts using the installer on their website, installing Node is pretty much this simple:

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

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

Found 2 ports.
--
npm @1.2.21 (devel)
    node package manager
$ sudo port install nodejs npm
.. long log of downloading...

Installing the StrongLoop Node distribution


StrongLoop (http://strongloop.com) has put together a supported version of Node that is prepackaged with several useful tools. This is a Node distribution in the same sense in which Fedora or Ubuntu are Linux distributions. StrongLoop brings together several useful packages, some of which were written by StrongLoop. StrongLoop tests the packages together, and distributes installable bundles through their website.

The packages in the distribution include Express, Passport, Mongoose, Socket.IO, Engine.IO, Async, and Request. We will use all of those modules in this book.

To install, navigate to the company home page and click on the Products link. They offer downloads of precompiled packages for both RPM and Debian Linux systems, as well as Mac OS X and Windows. Simply download the appropriate bundle for your system.

For the RPM bundle, type the following:

$ sudo rpm -i bundle-file-name

For the Debian bundle, type the following:

$ sudo dpkg -i bundle...

Installing from source on POSIX-like systems


Installing the pre-packaged Node distributions is currently the preferred installation method. However, installing Node from source is desirable in a few situations:

  • It could let you optimize the compiler settings as desired

  • It could let you cross-compile, say for an embedded ARM system

  • You might need to keep multiple Node builds for testing

  • You might be working on Node 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 Node wiki at https://github.com/joyent/node/wiki/Installation.

Installing prerequisites

As noted a minute ago, there are three prerequisites, a C compiler, Python, and the OpenSSL libraries. The Node installation process...

Installing developer tools on Mac OS X


The developer tools (such as GCC) are an optional installation on Mac OS X. There are two ways to get those tools, both of which are free. On the OS X installation DVD is a directory labeled Optional Installs, in which there is a package installer for—among other things—the developer tools, including Xcode.

The other method is to download the latest copy of Xcode (for free) from http://developer.apple.com/xcode/.

Most other POSIX-like systems, such as Linux, include a C compiler with the base system.

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:

$ mkdir src
$ cd src
$ wget http://nodejs.org/dist/v0.10.7/node-v0.10.7.tar.gz
$ tar xvfz node-v0.10.7.tar.gz
$ cd node-v0.10.7

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 can see its long list of...

Run a few commands; testing the commands


Now that you've installed Node, we want to do two things; verify that the installation was successful, and familiarize you with the command-line tools.

Node's command-line tools

The basic install of Node includes two commands, node and node-waf. We've already seen node in action. It's used either for running command-line scripts or server processes. The other, node-waf, is a build tool for Node native extensions. Since it's for building native extensions, we will not cover it in this book and you should consult the online documentation at nodejs.org.

The easiest way to verify whether your Node installation works is also the best way to get help with Node. Type the following:

$ node –-help
Usage: node [options] [ -e script | script.js ] [arguments]
       node debug script.js [arguments]

Options:
  -v, --version        print node's version
  -e, --eval script    evaluate script
  -p, --print          print result of --eval
  -i, --interactive    always...

npm – the Node package manager


Node by itself is a pretty basic system, being a JavaScript interpreter with a few interesting asynchronous I/O libraries. One of the things which makes Node interesting is the rapidly growing ecosystem of third party modules for Node. At the center of that ecosystem is npm. The modules can be downloaded at source and assembled manually for use with Node programs. The npm command gives us a simpler way; npm is the de-facto standard package manager for Node and it greatly simplifies downloading and using these modules. We will talk about npm at length in the next chapter.

The sharp-eyed will have noticed that npm is already installed via all the installation methods already discussed. In the past, npm was installed separately, but today it is bundled with Node.

Now that we have npm installed, let's take it for a quick spin. Hexy is a utility program for printing hex dumps of files. It serves our purpose right now in giving us something to quickly install and try...

Starting Node servers at system startup


Earlier we started a Node server from the command line. While this is useful for testing and development, it's not useful for deploying an application in any normal sense. There are normal practices for starting server processes, which differ for each operating system. Implementing a Node server means starting it similarly to the other background processes (sshd, Apache, MySQL, and so on) using, for example, start/stop scripts.

The Node project does not include start/stop scripts for any operating system. It can be argued that it would be out of place for Node to include such scripts. Instead, Node server applications should include such scripts. The traditional way is that the init daemon manages background processes using scripts in the /etc/init.d directory. On Fedora and Red Hat, that's still the process, but other operating systems use other daemon managers such as Upstart or launchd.

Writing these start/stop scripts is only a part of what's required...

Summary


We learned a lot in this chapter, about installing Node, using its command-line tools, and how to run a Node server. We also breezed past a lot of details that will be covered later in the book, so be patient.

Specifically, we covered:

  • Downloading and compiling the Node source code

  • Installing Node either for development use in your home directory, or for deployment in system directories

  • Installing Node Package Manager (npm), the de-facto standard package manager used with Node

  • Running Node scripts or Node servers

  • What's required to use Node for a reliable background process

Now that we've seen how to set up the basic system, we're ready to start working on implementing applications with Node. First we must learn the basic building block of Node applications, modules, which is the topic of the next chapter.

Left arrow icon Right arrow icon

What you will learn

  • Discover the role of server-side JavaScript in web application development
  • Explore architecture choices in Node.js for performance and throughput
  • Install and use Node.js for both development and deployment
  • Use the Connect and Express application frameworks
  • Deploy both SQL and MongoDB database systems

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 19, 2013
Length: 248 pages
Edition :
Language : English
ISBN-13 : 9781782163312
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 : Jul 19, 2013
Length: 248 pages
Edition :
Language : English
ISBN-13 : 9781782163312
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 121.97
Mastering Node.js
€41.99
Node Web Development - Second Edition
€37.99
Express Web Application Development
€41.99
Total 121.97 Stars icon

Table of Contents

9 Chapters
About Node Chevron down icon Chevron up icon
Setting up Node Chevron down icon Chevron up icon
Node Modules Chevron down icon Chevron up icon
HTTP Servers and Clients – A Web Application's First Steps Chevron down icon Chevron up icon
Implementing a Simple Express Application Chevron down icon Chevron up icon
Data Storage and Retrieval Chevron down icon Chevron up icon
Multiuser Authorization, Deployment, Scaling, and Hosting Chevron down icon Chevron up icon
Dynamic Interaction between the Client and Server Application Chevron down icon Chevron up icon
Unit Testing Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(1 Ratings)
5 star 0%
4 star 100%
3 star 0%
2 star 0%
1 star 0%
E.E. Feb 17, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
David Herron explains Node.js concepts clearly. The chapters are interactive, with step-by-step instructions that are helpful in understanding the concepts. Each focuses on a small project, and the later ones build off previous projects in a way that works well for this type of book.I've taken off one star only for the book's sometimes confusing mistakes. For instance, in the chapter on Socket.IO, Herron says to modify some code that's shown in a snippet. The only problem is that we haven't yet written the last third of the code to be able to modify it yet. The errors can usually be worked around without much hassle, but they can be frustrating for those following along.
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.