Chapter 2
Server-side environment
Databases hosted by MongoLab could be accessed directly from AngularJS
applications through the REST interface. While talking to MongoLab directly from
a browser might be a good approach for very simple projects; it is not an option one
would choose for any real-life, public-facing application. There is simply not enough
security built in into the MongoLab offering.
In practice most of the UIs written in AngularJS will communicate with some kind
of back-end to retrieve data. A middleware will typically provide security services
(authentication) and will verify access rights (authorization) as well. Our sample
application is no different and needs a back-end. Once again, we are going to bet on
JavaScript-based solution; node.js.
The node.js binaries are available for all popular operating systems, and can be
obtained from http://nodejs.org/. You need to download and install node.js
runtime in order to be able to run examples from this book on your local machine.
Introducing node.js is well beyond the scope of this book. Fortunately
only very basic knowledge of node.js and its package manager
(node.js package manager – npm) is needed to run the examples
from this book. Developers familiar with node.js will find it easier
to understand what is happening on the server-side end of the sample
application, but node.js knowledge is not mandatory to follow and
understand AngularJS examples from this book.
Apart from the node.js itself we are going to use the following node.js libraries to
build server-side components of the sample application:
- Express (http://expressjs.com/) as the server-side web application
framework that can provide routing, serve data and static resources. - Passport (http://passportjs.org/) as a security middleware for node.js.
- Restler (https://github.com/danwrong/restler) as an HTTP client library
for node.js.
While familiarity with node.js and the mentioned libraries might be helpful it is not
necessary to effectively learn AngularJS. You might want to dive into node.js and
the listed libraries, if you want to gain deeper understanding of the server-side part
of examples we've prepared for this book. If, on the other hand, your work involves
using different back-end you may safely ignore most of the node.js related details.