MEAN WEB / DEVELOPMENT
- 1a Edición
- Reino Unido PACKT 2014
- 334 Ilustración 19.4 X 23.4 CM
Table of contents : Cover......Page 1 Copyright......Page 3 Credits......Page 4 About the Author......Page 5 About the Reviewers......Page 6 www.PacktPub.com......Page 8 Table of Contents......Page 10 Preface......Page 18 Chapter 1: Introduction to MEAN......Page 24 Three-tier web application development......Page 25 The evolution of JavaScript......Page 26 Introducing MEAN......Page 27 Installing MongoDB......Page 28 Running MongoDB manually......Page 29 Running MongoDB as a Windows Service......Page 30 Installing MongoDB from binaries......Page 31 Install MongoDB using a package manager......Page 32 Using the MongoDB shell......Page 33 Installing Node.js on Windows......Page 34 Installing Node.js on Mac OS X......Page 36 Running Node.js......Page 37 Using NPM......Page 38 The installation process of NPM......Page 39 Managing dependencies using the package.json file......Page 41 Summary......Page 44 Chapter 2: Getting Started with Node.js......Page 46 Introduction to Node.js......Page 47 JavaScript event-driven programming......Page 48 Node.js event-driven programming......Page 50 JavaScript closures......Page 51 CommonJS modules......Page 53 Node.js core modules......Page 55 Node.js folder modules......Page 56 Developing Node.js web applications......Page 57 Meet the Connect module......Page 59 Connect middleware......Page 61 Understanding the order of Connect middleware......Page 63 Mounting Connect middleware......Page 64 Summary......Page 65 Introduction to Express......Page 66 Installing Express......Page 67 Creating your first Express application......Page 68 The application object......Page 69 The request object......Page 70 The response object......Page 71 Implementing the MVC pattern......Page 72 Horizontal folder structure......Page 73 Vertical folder structure......Page 75 Files naming conventions......Page 78 Implementing the horizontal folder structure......Page 79 Configuring an Express application......Page 83 Environment configuration files......Page 86 Rendering views......Page 87 Configuring the view system......Page 88 Rendering EJS views......Page 89 Serving static files......Page 90 Configuring sessions......Page 92 Summary......Page 94 Introduction to NoSQL......Page 96 Introducting MongoDB......Page 99 The BSON format......Page 100 MongoDB ad hoc queries......Page 101 MongoDB indexing......Page 102 MongoDB replica set......Page 103 MongoDB sharding......Page 104 MongoDB shell......Page 105 MongoDB collections......Page 106 Creating a document using update......Page 108 Using an equality statement......Page 109 Updating existing documents......Page 110 Updating documents using save......Page 111 Deleting all documents......Page 112 Summary......Page 113 Introducing Mongoose......Page 114 Connecting to MongoDB......Page 115 Creating the user schema and model......Page 117 Creating new users using save......Page 118 Finding multiple user documents using find......Page 121 Advanced querying using find......Page 122 Reading a single user document using findOne......Page 123 Updating an existing user document......Page 124 Deleting an existing user document......Page 125 Defining default values......Page 127 Predefined modifiers......Page 128 Custom setter modifiers......Page 129 Custom getter modifiers......Page 130 Optimizing queries using indexes......Page 131 Defining custom static methods......Page 133 Model validation......Page 134 Predefined validators......Page 135 Custom validators......Page 136 Using post middleware......Page 137 Using Mongoose DBRef......Page 138 Summary......Page 140 Chapter 6: Managing User Authentication Using Passport......Page 142 Installing Passport......Page 143 Configuring Passport......Page 144 Installing Passport's local strategy module......Page 146 Configuring Passport's local strategy......Page 147 Adapting the User model......Page 149 Creating the authentication views......Page 152 Modifying the user controller......Page 154 Displaying flash error messages......Page 156 Wiring the user's routes......Page 160 Handling OAuth user creation......Page 162 Using Passport's Facebook strategy......Page 164 Using Passport's Twitter strategy......Page 168 Using Passport's Google strategy......Page 172 Summary......Page 177 Chapter 7: Introduction to AngularJS......Page 178 AngularJS modules......Page 179 Third-party modules......Page 180 Two-way data binding......Page 181 Dependency injection......Page 182 Dependency injection in AngularJS......Page 183 Core directives......Page 184 Automatic bootstrap......Page 185 Meeting the Bower dependencies manager......Page 186 Configuring the Bower dependencies manager......Page 187 Configuring AngularJS......Page 188 Structuring an AngularJS application......Page 189 Bootstrapping your AngularJS application......Page 193 AngularJS MVC entities......Page 194 AngularJS views......Page 196 AngularJS controllers and scopes......Page 197 AngularJS routing......Page 199 Installing the ngRoute module......Page 200 Configuring the URL scheme......Page 201 AngularJS application routes......Page 202 AngularJS prebundled services......Page 204 Creating AngularJS services......Page 205 Managing AngularJS authentication......Page 206 Rendering the user object......Page 207 Adding the Authentication service......Page 208 Using the Authentication service......Page 210 Summary......Page 211 Chapter 8: Creating a MEAN CRUD Module......Page 212 Creating the Mongoose model......Page 213 The error handling method of the Express controller......Page 215 The list method of the Express controller......Page 216 The read middleware of the Express controller......Page 217 The update method of the Express controller......Page 218 The delete method of the Express controller......Page 219 Implementing an authentication middleware......Page 220 Wiring the Express routes......Page 221 Configuring the Express application......Page 223 Introducing the ngResource module......Page 224 Installing the ngResource module......Page 225 Using the $resource service......Page 227 Implementing the AngularJS MVC module......Page 228 Setting up the AngularJS module controller......Page 229 The create method of the AngularJS controller......Page 230 The find and findOne methods of the AngularJS controller......Page 231 The delete method of the AngularJS controller......Page 232 The create-article view......Page 233 The view-article view......Page 234 The edit-article view......Page 235 The list-articles view......Page 236 Wiring the AngularJS module routes......Page 237 Finalizing your module implementation......Page 238 Summary......Page 240 Chapter 9: Adding Real-time Functionality Using Socket.io......Page 242 Introducing WebSockets......Page 243 Introducing Socket.io......Page 244 The Socket.io server object......Page 245 The Socket.io configuration middleware......Page 246 The Socket.io client object......Page 247 Socket.io events......Page 248 Handling events......Page 249 Emitting events......Page 250 Socket.io server namespaces......Page 251 Joining and leaving rooms......Page 252 Emitting events to rooms......Page 253 Installing Socket.io......Page 254 Configuring the Socket.io server......Page 255 Configuring the Socket.io session......Page 256 Installing the connect-mongo and cookie-parser modules......Page 257 Configuring the connect-mongo module......Page 258 Configuring the Socket.io session......Page 260 Setting the event handlers of the chat server......Page 261 Creating the Socket service......Page 264 Creating the chat controller......Page 265 Creating the chat view......Page 266 Adding chat routes......Page 267 Finalizing the chat implementation......Page 268 Summary......Page 270 Chapter 10: Testing MEAN Applications......Page 272 TDD, BDD, and unit testing......Page 273 Test runners......Page 275 Introducing Mocha......Page 276 Introducing Should.js......Page 277 Installing Mocha......Page 278 Installing the Should.js and SuperTest modules......Page 279 Configuring your test environment......Page 280 Writing your first Mocha test......Page 281 Testing the Express model......Page 282 Testing the Express controller......Page 284 Running your Mocha test......Page 286 Introducing the Jasmine framework......Page 288 Introducing Karma test runner......Page 289 Installing Karma's dependencies......Page 290 Configuring the Karma test runner......Page 291 Mocking AngularJS components......Page 293 Writing AngularJS unit tests......Page 294 Writing your first unit test......Page 298 AngularJS E2E tests......Page 301 Introducing the Protractor test runner......Page 302 Installing the Protractor test runner......Page 303 Writing your first E2E test......Page 304 Running your AngularJS E2E tests......Page 305 Summary......Page 306 Chapter 11: Automating and Debugging MEAN Applications......Page 308 Installing the Grunt task runner......Page 309 Configuring Grunt......Page 311 Running your application using Grunt......Page 312 Testing your application using Grunt......Page 314 Linting your application using Grunt......Page 318 Watching file changes using Grunt......Page 321 Installing node-inspector's grunt task......Page 325 Configuring node-inspector's grunt task......Page 327 Running the debug grunt task......Page 330 Debugging AngularJS with Batarang......Page 331 Using Batarang......Page 332 Batarang Models......Page 333 Batarang Performance......Page 334 Batarang Dependencies......Page 335 Summary......Page 336 Index......Page 338
The MEAN stack is a collection of the most popular modern tools for web development; it comprises MongoDB, Express, AngularJS, and Node.js. Starting with MEAN core frameworks, this project-based guide will explain the key concepts of each framework, how to set them up properly, and how to use popular modules to connect it all together. By following the real-world examples shown in this tutorial, you will scaffold your MEAN application architecture, add an authentication layer, and develop an MVC structure to support your project development. Finally, you will walk through the different tools and frameworks that will help expedite your daily development cycles. Watch how your application development grows by learning from the only guide that is solely orientated towards building a full, end-to-end, real-time application using the MEAN stack! Who is this book for? If you are a web or a full-stack JavaScript developer who is interested in learning how to build modern web applications using the MEAN stack, this book is for you.