Full Stack JavaScript Development With MEAN
320 Pages
English

Full Stack JavaScript Development With MEAN

-

Description

With modern tools. it is possible to create a production grade, full-stack application using HTML, CSS, and JavaScript alone. The combination of MongoDB, Express, AngularJS, and Node.js has become so popular that it has earned the title MEAN stack -- the subject of this book.

This book explores the MEAN stack in detail. We will begin by covering Node.js, as it will lay the groundwork for all of our server-side work. You will learn how to get Node running on your local machine as well as download modules using npm. The key aspects of the Node.js programming model will also be covered.

From there, we will move on to MongoDB, where you'll learn how to interact with Mongo from a Node application. You will also learn how to create, retrieve, update, and delete data from a Mongo store.

After you have a solid grasp on Node and Mongo, the book will move on to the Express web server. We'll cover the basics of Express applications via topics like routes and middleware. Building on previous chapters, we will cover the integration of Node, Mongo, and Express.

Our coverage of the MEAN stack will wrap up with several chapters on AngularJS. These chapters will cover Angular fundamentals like data binding, directives, controllers, routing, and services. In an effort to explore competing technologies, a slight introduction to Ember.js will also be provided.

Full stack JavaScript is not fully encompassed by the MEAN stack. There is an entire ecosystem of JavaScript tools to learn about, and this book will introduce a few of them. We will cover task runners Gulp.js and Grunt.js which are extremely useful for automating mundane, repetitive tasks. We'll also cover JSHint, a linting tool used to improve code quality. Linting tools analyze source code and report potentials issues - a feature that is especially useful in non-compiled languages like JavaScript.


Subjects

Informations

Published by
Published 24 December 2014
Reads 49
EAN13 9781457192357
Language English
Document size 4 MB

Legal information: rental price per page €. This information is given for information only in accordance with current legislation.

Summary of Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2. Node.js Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3. Modules and npm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 4. Node’s Programming Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 5. Core Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 6. Building the Node Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 7. MongoDB Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 8. Interacting with MongoDB Using Mongoose . . . . . . . . . . . . . . . . . . . . . . . . . 99 9. Using MongoDB and Mongoose in Our Sample App . . . . . . . . . . . . . . . . . 115 10. Alternatives to Mongo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 11. Introduction to Express . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 12. Architecture of an Express Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 13. Using Express in Our App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14. Alternative Server Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 15. AngularJS Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 16. Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 17. Angular Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 18. Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 19. Clientside Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 20. Angular in Our App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 21. Task Runners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 22. Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 23. Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
FULL STACK JAVASCRIPT DEVELOPMENT WITH MEAN
BYADAM BRETZ & COLIN J. IHRIG
iv
Full Stack JavaScript Development with MEAN by Adam Bretz and Colin J. Ihrig
Copyright©2014 SitePoint Pty. Ltd.
Product Manager: Simon Mackie Technical Editor: Don Nguyen
English Editor: Kelly Steele Cover Designer: Alex Walker
Notice of Rights 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 embodied in critical articles or reviews.
Notice of Liability The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.
Trademark Notice Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.
Published by SitePoint Pty. Ltd.
48 Cambridge Street Collingwood VIC Australia 3066 Web: www.sitepoint.com Email: business@sitepoint.com
ISBN 9780992461256 (print)
ISBN 9780992461249 (ebook) Printed and bound in the United States of America
About Adam Bretz
Adam Bretz is a software engineer focusing on client and server side JavaScript. Adam earned his Bachelor of Science in Computer Science in 2007 from Millersville University of Pennsylvania. At a previous job, Adam was part of the team of engineers that helped migrate the company from PHP to a pure JavaScript solution. Adam currently resides in the Pittsburgh area with his wife, Jenna.
About Colin J. Ihrig
Colin J. Ihrig is a software engineer, working primarily with Node.js. Colin is the author of Pro Node.js for Developers, and is currently the managing editor of SitePoint's JavaScript channel. Colin received his Bachelor of Science in Engineering, and Master of Science in Computer Engineering from the University of Pittsburgh in 2005 and 2008, respectively.
About SitePoint
SitePoint specializes in publishing fun, practical, and easytounderstand content for web professionals. Visit http://www.sitepoint.com/ to access our blogs, books, newsletters, articles, and community forums. You’ll find a stack of information on JavaScript, PHP, Ruby, mobile development, design, and more.
v
To Mom and Dadthanks for getting me a Nintendo when I was seven and a computer when I was ten.Adam
This book is dedicated to my wife, Alaina, my sons, CJ and Carter, and my mom. I love you all so much!Colin
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Conventions Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Code Samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Tips, Notes, and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Supplementary Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Want to Take Your Learning Further? . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Chapter 1Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 The Rise of Fullstack JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 The Node.js Ecosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 2Node.js Introduction. . . . . . . . . . . . . . . . . . . . 11 Familiarity with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 The Problem with I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 An Example Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Stepping Around the I/O Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Real World Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Your First Node.js Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Installing Node.js . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 REPL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Writing the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20