Preface |
|
xv | |
Acknowledgments |
|
xvii | |
About this book |
|
xix | |
|
Part 1 Setting The Baseline |
|
|
1 | (50) |
|
1 Introducing full-stack development |
|
|
3 | (21) |
|
1.1 Why learn the full stack? |
|
|
4 | (3) |
|
A very brief history of web development |
|
|
4 | (2) |
|
The trend toward full-stack developers |
|
|
6 | (1) |
|
Benefits of full-stack development |
|
|
6 | (1) |
|
Why the MEAN stack specifically? |
|
|
7 | (1) |
|
1.2 Introducing Node.js: The web server/platform |
|
|
7 | (5) |
|
JavaScript: The single language through the stack |
|
|
8 | (1) |
|
Fast, efficient, and scalable |
|
|
8 | (3) |
|
Using prebuilt packages via npm |
|
|
11 | (1) |
|
1.3 Introducing Express: The framework |
|
|
12 | (1) |
|
|
12 | (1) |
|
Routing URLs to responses |
|
|
12 | (1) |
|
|
12 | (1) |
|
Remembering visitors with session support |
|
|
13 | (1) |
|
1.4 Introducing MongoDB: The database |
|
|
13 | (3) |
|
Relational versus document databases |
|
|
13 | (1) |
|
MongoDB documents: JavaScript data store |
|
|
14 | (1) |
|
More than just a document database |
|
|
14 | (1) |
|
What is MongoDB not good for? |
|
|
15 | (1) |
|
Mongoose for data modeling and more |
|
|
15 | (1) |
|
1.5 Introducing AngularJS: The front-end framework |
|
|
16 | (3) |
|
|
16 | (1) |
|
Two-way data binding: Working with data in a page |
|
|
16 | (2) |
|
Using AngularJS to load new pages |
|
|
18 | (1) |
|
|
18 | (1) |
|
|
19 | (2) |
|
Twitter Bootstrap for user interface |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
20 | (1) |
|
1.7 Putting it together with a practical example |
|
|
21 | (2) |
|
Introducing the example application |
|
|
21 | (1) |
|
How the MEAN stack components work together |
|
|
22 | (1) |
|
|
23 | (1) |
|
2 Designing a MEAN stack architecture |
|
|
24 | (27) |
|
2.1 A common MEAN stack architecture |
|
|
25 | (1) |
|
|
26 | (2) |
|
|
26 | (1) |
|
Analytics and browser history |
|
|
27 | (1) |
|
|
27 | (1) |
|
|
28 | (1) |
|
2.3 Designing a flexible MEAN architecture |
|
|
28 | (6) |
|
Requirements for a blog engine |
|
|
29 | (1) |
|
A blog engine architecture |
|
|
30 | (3) |
|
Best practice: Build an internal API for a data layer |
|
|
33 | (1) |
|
2.4 Planning a real application |
|
|
34 | (6) |
|
Planning the application at a high level |
|
|
35 | (1) |
|
Architecting the application |
|
|
36 | (2) |
|
Wrapping everything in an Express project |
|
|
38 | (1) |
|
|
39 | (1) |
|
2.5 Breaking the development into stages |
|
|
40 | (7) |
|
Rapid prototype development stages |
|
|
40 | (1) |
|
|
41 | (6) |
|
2.6 Hardware architecture |
|
|
47 | (2) |
|
|
47 | (1) |
|
|
47 | (2) |
|
|
49 | (2) |
|
Part 2 Building A Node Web Application |
|
|
51 | (340) |
|
3 Creating and setting up a MEAN project |
|
|
53 | (27) |
|
3.1 A brief look at Express, Node, and npm |
|
|
55 | (3) |
|
Defining packages with package.json |
|
|
55 | (1) |
|
Installing Node dependencies with npm |
|
|
56 | (2) |
|
3.2 Creating an Express project |
|
|
58 | (6) |
|
|
58 | (1) |
|
Creating a project folder |
|
|
58 | (1) |
|
Configuring an Express installation |
|
|
59 | (2) |
|
Creating an Express project and trying it out |
|
|
61 | (1) |
|
Restarting the application |
|
|
62 | (2) |
|
3.3 Modifying Express for MVC |
|
|
64 | (6) |
|
|
64 | (1) |
|
Changing the folder structure |
|
|
65 | (1) |
|
Using the new views and routes folders |
|
|
66 | (1) |
|
Splitting controllers from routes |
|
|
67 | (3) |
|
3.4 Import Bootstrap for quick, responsive layouts |
|
|
70 | (4) |
|
Download Bootstrap and add it to the application |
|
|
70 | (1) |
|
Using Bootstrap in the application |
|
|
70 | (4) |
|
3.5 Make it live on Heroku |
|
|
74 | (5) |
|
|
74 | (2) |
|
Pushing the site live using Git |
|
|
76 | (3) |
|
|
79 | (1) |
|
4 Building a static site with Node and Express |
|
|
80 | (40) |
|
4.1 Defining the routes in Express |
|
|
82 | (2) |
|
Different controller files for different collections |
|
|
83 | (1) |
|
4.2 Building basic controllers |
|
|
84 | (3) |
|
|
85 | (1) |
|
Testing the controllers and routes |
|
|
86 | (1) |
|
|
87 | (11) |
|
|
88 | (1) |
|
Setting up the HTML framework with Jade templates and Bootstrap |
|
|
89 | (4) |
|
|
93 | (5) |
|
4.4 Adding the rest of the views |
|
|
98 | (8) |
|
|
98 | (4) |
|
|
102 | (2) |
|
|
104 | (2) |
|
4.5 Take the data out of the views and make them smarter |
|
|
106 | (13) |
|
How to move data from the view to the controller |
|
|
107 | (2) |
|
Dealing with complex, repeating data |
|
|
109 | (4) |
|
Manipulating the data and view with code |
|
|
113 | (1) |
|
Using includes and mixins to create reusable layout components |
|
|
113 | (2) |
|
|
115 | (2) |
|
Updating the rest of the views and controllers |
|
|
117 | (2) |
|
|
119 | (1) |
|
5 Building a data model with MongoDB and Mongoose |
|
|
120 | (40) |
|
5.1 Connecting the Express application to MongoDB using Mongoose |
|
|
122 | (8) |
|
Adding Mongoose to our application |
|
|
123 | (1) |
|
Adding a Mongoose connection to our application |
|
|
124 | (6) |
|
|
130 | (4) |
|
What is Mongoose and how does it work? |
|
|
131 | (3) |
|
5.3 Defining simple Mongoose schemas |
|
|
134 | (13) |
|
The basics of setting up a schema |
|
|
135 | (2) |
|
Using geographic data in MongoDB and Mongoose |
|
|
137 | (1) |
|
Creating more complex schemas with subdocuments |
|
|
138 | (5) |
|
|
143 | (2) |
|
Compiling Mongoose schemas into models |
|
|
145 | (2) |
|
5.4 Using the MongoDB shell to create a MongoDB database and add data |
|
|
147 | (5) |
|
|
147 | (1) |
|
Creating a MongoDB database |
|
|
148 | (4) |
|
5.5 Getting our database live |
|
|
152 | (7) |
|
Setting up MongoLab and getting the database URI |
|
|
152 | (2) |
|
|
154 | (2) |
|
Making the application use the right database |
|
|
156 | (3) |
|
|
159 | (1) |
|
6 Writing a REST API: Exposing the MongoDB database to the application |
|
|
160 | (42) |
|
6.1 The rules of a REST API |
|
|
161 | (6) |
|
|
162 | (1) |
|
|
163 | (2) |
|
Responses and status codes |
|
|
165 | (2) |
|
6.2 Setting up the API in Express |
|
|
167 | (5) |
|
|
167 | (3) |
|
Creating the controller placeholders |
|
|
170 | (1) |
|
|
171 | (1) |
|
|
172 | (1) |
|
6.3 GET methods: Reading data from MongoDB |
|
|
172 | (15) |
|
Finding a single document in MongoDB using Mongoose |
|
|
173 | (4) |
|
Finding a single subdocument based on IDs |
|
|
177 | (3) |
|
Finding multiple documents with geospatial queries |
|
|
180 | (7) |
|
6.4 POST methods: Adding data to MongoDB |
|
|
187 | (6) |
|
Creating new documents in MongoDB |
|
|
188 | (2) |
|
Creating new subdocuments in MongoDB |
|
|
190 | (3) |
|
6.5 PUT methods: Updating data in MongoDB |
|
|
193 | (4) |
|
Using Mongoose to update a document in MongoDB |
|
|
194 | (2) |
|
Updating an existing subdocument in MongoDB |
|
|
196 | (1) |
|
6.6 DELETE method: Deleting data from MongoDB |
|
|
197 | (3) |
|
Deleting documents in MongoDB |
|
|
198 | (1) |
|
Deleting a subdocument from MongoDB |
|
|
199 | (1) |
|
|
200 | (2) |
|
7 Consuming a REST API: Using an API from inside Express |
|
|
202 | (189) |
|
7.1 How to call an API from Express |
|
|
203 | (3) |
|
Adding the request module to our project |
|
|
203 | (1) |
|
Setting up default options |
|
|
204 | (1) |
|
|
204 | (2) |
|
7.2 Using lists of data from an API: The Loc8r homepage |
|
|
206 | (10) |
|
Separating concerns: Moving the rendering into a named function |
|
|
207 | (1) |
|
|
207 | (1) |
|
Using the API response data |
|
|
208 | (1) |
|
Modifying data before displaying it: Fixing the distances |
|
|
209 | (3) |
|
Catching errors returned by the API |
|
|
212 | (4) |
|
7.3 Getting single documents from an API: The Loc8r Details page |
|
|
216 | (10) |
|
Setting URLs and routes to access specific MongoDB documents |
|
|
216 | (2) |
|
Separating concerns: Moving the rendering into a named function |
|
|
218 | (1) |
|
Querying the API using a unique ID from a URL parameter |
|
|
219 | (1) |
|
Passing the data from the API to the view |
|
|
220 | (1) |
|
Debugging and fixing the view errors |
|
|
221 | (2) |
|
Creating status-specific error pages |
|
|
223 | (3) |
|
7.4 Adding data to the database via the API: Add Loc8r reviews |
|
|
226 | (128) |
|
Setting up the routing and views |
|
|
227 | (4) |
|
POSTing the review data to the API |
|
|
231 | (123) |
|
11.2 Creating a user schema for MongoDB |
|
|
354 | (6) |
|
One-way password encryption: Hashes and salts |
|
|
354 | (1) |
|
Building the Mongoose schema |
|
|
354 | (1) |
|
Setting encrypted paths using Mongoose methods |
|
|
355 | (2) |
|
Validating a submitted password |
|
|
357 | (1) |
|
Generating a JSON Web Token |
|
|
357 | (3) |
|
11.3 Creating an authentication API with Passport |
|
|
360 | (8) |
|
Installing and configuring Passport |
|
|
360 | (3) |
|
Creating API endpoints to return JSON Web Tokens |
|
|
363 | (5) |
|
11.4 Securing relevant API endpoints |
|
|
368 | (5) |
|
Adding authentication middleware to Express routes |
|
|
368 | (1) |
|
Using the JWT information inside a controller |
|
|
369 | (4) |
|
11.5 Creating Angular authentication service |
|
|
373 | (4) |
|
Managing a user session in Angular |
|
|
373 | (1) |
|
Allowing users to sign up, sign in, and sign out |
|
|
374 | (1) |
|
Using the JWT data in the Angular service |
|
|
375 | (2) |
|
11.6 Creating register and login pages |
|
|
377 | (6) |
|
Building the register page |
|
|
377 | (3) |
|
|
380 | (3) |
|
11.7 Working with authentication in the Angular app |
|
|
383 | (6) |
|
|
383 | (3) |
|
Adding user data to a review |
|
|
386 | (3) |
|
|
389 | (2) |
Appendix A Installing the stack |
|
391 | (4) |
Appendix B Installing and preparing the supporting cast |
|
395 | (4) |
Appendix C Dealing with all of the views |
|
399 | (6) |
Appendix D Reintroducing JavaScript available online only index |
|
405 | |