Node Web Development
eBook - ePub

Node Web Development

  1. 172 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Node Web Development

About this book

In Detail

Node is an exciting new technology stack that brings JavaScript to the server-side of web applications for the first time. Node means that JavaScript is no longer just for browsers. It's for web application development, it's for developing any internet protocol, it's for the real-time web, it's for command line scripts, and much more.

Node Web Development gives you an excellent starting point straight into the heart of developing server side web applications with node. You will learn, through practical examples, how to use the HTTP Server and Client objects, the Connect and Express application frameworks, the algorithms for asynchronous execution, and use both SQL and MongoDB databases.

This book is the ideal companion for getting started with Node. Starting with practical advice on installing Node for both development and application deployment, you will learn how to develop both HTTP Server and Client applications. Many different ways of working with Node are shown, including using database storage engines in applications and developing websites both with and without the Connect/Express web application framework. You will also get an introduction to Node's CommonJS module system allowing you to implement an important subset of object-oriented design.

Approach

This book is a practical introduction to learning about Node. Each chapter introduces you to a different area of Node, using screenshots and examples to get you up and running as quickly as possible.

Who this book is for

If you are a developer who wants to use JavaScript on the server side in order to build quicker, higher performing web applications, then this book is for you. It is recommended that you should have at least a rudimentary understanding of JavaScript and web application development.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Node Web Development


Table of Contents

Node Web Development
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. What is Node?
What can you do with Node?
Server-side JavaScript
Why should you use Node?
Architecture: Threads versus asynchronous event-driven
Performance and utilization
Server utilization, the bottom line, and green web hosting
Spelling: Node, Node.js, or Node.JS?
Summary
2. Setting up Node
System requirements
Installation on POSIX-like systems (Linux, Solaris, Mac, and so on)
Installing prerequisites
Installing developer tools on Mac OS X
Installing in your home directory
What's the rationale for a home directory installation?
Installing in a system-wide directory
Installing on Mac OS X with MacPorts
Installing on Mac OS X with homebrew
Installing on Linux from package management systems
Maintaining multiple Node installs simultaneously
Run a few commands; test your installation
Node's command-line tools
Running a simple script with Node
Launching a server with Node
Installing npm—the Node package manager
Starting Node servers at system startup
Using all CPU cores on multi-core systems
Summary
3. Node Modules
What's a module?
Node modules
How does Node resolve require('module')?
Module identifiers and path names
Local modules within your application
Bundling external dependencies with your application
System-wide modules in the require.paths directories
Complex modules—modules as directories
Node package Manager (npm)
npm package format
Finding npm packages
Using the npm commands
Getting help with npm
Viewing package information
Installing an npm package
Using installed packages
What packages are currently installed?
Package scripts
Editing and exploring installed package content
Updating outdated packages you've installed
Uninstalling an installed npm package
Developing and publishing npm packages
npm configuration settings
Package version strings and ranges
CommonJS modules
Demonstrating module encapsulation
Summary
4. Variations on a Simple Application
Creating a Math Wizard
To use a web framework, or not
Implementing the Math Wizard with Node (no frameworks)
Routing requests in Node
Handling URL query parameters
Multiplying numbers
Calculating the other mathematical functions
Extending the Math Wizard
Long running calculations (fibonacci numbers)
What "complete web server" features are missing?
Using Connect to implement the Math Wizard
Installing Connect and other setup
Connecting with Connect
Using Express to implement the Math Wizard
Implementing the Express Math Wizard
Handling errors
Parameterized URLs and data services
Parametrized URLs in Express
The mathematics server (and client)
Refactoring Math Wizard to use math server
Summary
5. A Simple Web Server, EventEmitters, and HTTP Clients
Sending and receiving events with EventEmitters
EventEmitter theory
HTTP Sniffer—listening to the HTTP conversation
Implementing a basic web server
The Basic Server implementation
Basic Server core (basicserver.js)
The Favicon handler (faviconHandler.js)
The static file handler (staticHandler.js)
A configuration for Basic Server (server.js)
Virtual host configuration with Basic Server
A shorturl module for Basic Server
MIME types and the MIME npm package
Cookie handling
Virtual hosts and request routing
Making HTTP Client requests
Summary
6. Data Storage and Retrieval
Data storage engines for Node
SQLite3—Lightweight in-process SQL engine
Installation
Implementing the Notes application with SQLite3
Database abstraction module—notesdb-sqlite3.js
Initializing the database—setup.js
Display notes on the console—show.js
Putting together the Notes web application—app.js
Notes application templates
Running the SQLite3 Notes application
Handling and debugging errors
Using other SQL databases with Node
Mongoose—Node interface to MongoDB
Installing Mongoose
Implementing the Notes application with Mongoose
Database abstraction module—notesdb-mongoose.js
Initializing the database—setup.js
Display notes on the console—show.js
Putting it together in an application—app.js
Other MongoDB database support
A quick look at authenticating your users
Summary
Index

Node Web Development

Copyright © 2011 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: August 2011
Production Reference: 1020811
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-849515-14-6
www.packtpub.com
Cover Image by David Lorenz Winston ()

Credits

Author
David Herron
Reviewers
Blagovest Dachev
Matt Ranney
Acquisition Editor
Sarah Cullington
Development Editor
Pallavi Iyengar
Technical Editor
Joyslita D'Souza
Project Coordinator
Joel Goveya
Proofreader
Aaron Nash
Indexers
Hemangini Bari
Tejal Daruwale
Production Coordinator
Alwin Roy
Cover Work
Alwin Roy

About the Author

David Herron has worked in the software industry, holding both developer and quality engineering roles, in Silicon Valley for over 20 ye...

Table of contents

  1. Node Web Development

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Node Web Development by David Herron in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.