Book Image

Learning Single-page Web Application Development

Book Image

Learning Single-page Web Application Development

Overview of this book

Table of Contents (15 chapters)
Learning Single-page Web Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Dynamic web applications and real-time updates with no page refresh, scalable, high performance, and very rich interfaces are increasingly dominating the market for web development today with a new way to develop web content, called Single Page Web Application (SPA). This kind of development allows you to write less server-side code and more client-side code, which is sometimes focused on JavaScript, providing a better user experience with a new way to interact with the application. Products such as Gmail, Trello, and Groupon are examples of successful SPA development.

Throughout the book, we will show important points in the evaluation of the tools/frameworks available in the market for a great user experience with SPA development. Also, we introduce the concept of full-stack applications in JavaScript, using Node.js and MongoDB to build a RESTful API.

How to deal with all of these technologies and get the best out of them all is a very interesting and motivating task. In the course of our book, we will see how to get the best out of this development method, using the latest and greatest technologies to build a sample application.

Enjoy!

What this book covers

Chapter 1, Understanding Single Page Application, discusses the main concepts of the MVC pattern applied by different JavaScript libraries as MVC/MVVM/MV*. This chapter gives you an overview of the available tools and the peculiarities of the traditional web application and SPA. Also, we give some tips to choose the best framework for our project.

Chapter 2, Taking a Deep Dive into Node.js and MongoDB, dives into JavaScript on the server side and explains how to run a Node.js server. This chapter then presents the basic concepts such as the event loop, middleware, and Node Package Manager (NPM). We will see how to interact with MongoDB, which is one of the most popular NoSQL databases, using Mongoose ODM (Object Data Modeling) for Node applications.

Chapter 3, API with MongoDB and Node.js, explains how the RESTful API works and the six constraints to consider when creating an API RESTful architecture. We then get our hands dirty with the Express framework, coding the trivial CRUD (Create, Read, Update, Delete) operations for the baseline API.

Chapter 4, Creating a Conference Web Application, shows how to refactor the API using the Yeoman code generator and how to deal with user authentication using the Passport module and some template engines for Node.js to render HTML on the server.

Chapter 5, Starting with AngularJS, covers the core concepts about AngularJS, which is one of the most popular MV* framework, and explains how the framework deals with the MVC pattern, concepts such as two-way data binding, directives, and project organization to prepare the application to scale.

Chapter 6, Understanding Angular Views and Models, unleashes all the power of a generator to build the application scaffold. We will carefully examine the structure of SPA module-wise and rebuild our API using the help of the MEAN.JS generator, which is a powerful tool for creating applications with the MEAN (such as MongoDB, Express, AngularJS, Node.js) stack. We will use the RESTful interface of the WebStorm IDE to test the API.

Chapter 7, Testing Angular SPA with Karma and Protractor, details the basic concepts of tests and implements them using unit testing and e2e testing on SPA, with the help of testing frameworks such as Jasmine, Karma, and Protractor, using WebDriver and Selenium.

Chapter 8, Deploying the Application to the Cloud, takes a look at some important points involving the deploy process of all web applications, such as version control, deployment in the cloud and continuous deployment, and placement of the sample application in production.

What you need for this book

All examples in the book use open source solutions and can be downloaded for free from the links provided in each chapter.

The book's examples use many Node and Grunt modules and some JavaScript libraries, the most current version when writing this book. The examples use Express 4.2.0, a framework for Node. Here is the complete list of modules:

  • "body-parser": "~1.2.0"

  • "bower": "~1.3.1"

  • "compression": "~1.0.1"

  • "connect-flash": "~0.1.1"

  • "connect-mongo": "~0.4.0"

  • "consolidate": "~0.10.0"

  • "cookie-parser": "~1.1.0"

  • "express": "~4.2.0"

  • "express-session": "~1.1.0"

  • "forever": "~0.11.0"

  • "glob": "~3.2.9"

  • "grunt-cli": "~0.1.13"

  • "grunt-protractor-webdriver": "^0.1.8"

  • "helmet": "~0.2.1"

  • "lodash": "~2.4.1"

  • "method-override": "~1.0.0"

  • "mongoose": "~3.8.8"

  • "morgan": "~1.1.0"

  • "passport": "~0.2.0"

  • "passport-facebook": "~1.0.2"

  • "passport-google-oauth": "~0.1.5"

  • "passport-linkedin": "~0.1.3"

  • "passport-local": "~1.0.0"

  • "passport-twitter": "~1.0.2"

  • "protractor": "^1.2.0"

  • "swig": "~1.3.2"

  • "grunt-concurrent": "~0.5.0"

  • "grunt-contrib-csslint": "^0.2.0"

  • "grunt-contrib-cssmin": "~0.9.0"

  • "grunt-contrib-jshint": "~0.10.0"

  • "grunt-contrib-uglify": "~0.4.0"

  • "grunt-contrib-watch": "~0.6.1"

  • "grunt-env": "~0.4.1"

  • "grunt-karma": "~0.8.2"

  • "grunt-mocha-test": "~0.10.0"

  • "grunt-ngmin": "0.0.3"

  • "grunt-node-inspector": "~0.1.3"

  • "grunt-nodemon": "~0.2.1"

  • "grunt-protractor-runner": "^0.2.4"

  • "karma": "~0.12.0"

  • "karma-chrome-launcher": "~0.1.2"

  • "karma-coverage": "~0.2.0"

  • "karma-firefox-launcher": "~0.1.3"

  • "karma-jasmine": "~0.2.1"

  • "karma-phantomjs-launcher": "~0.1.2"

  • "load-grunt-tasks": "~0.4.0"

  • "should": "~3.3.1"

  • "supertest": "~0.12.1"

The following is the list of frontend dependencies:

  • "purecss": "~0.5.0"

    • "responsiveboilerplate": "2.3.2"

  • "bootstrap": "~3"

    • "angular": "~1.2"

    • "angular-resource": "~1.2"

    • "angular-mocks": "~1.2"

    • "angular-cookies": "~1.2"

    • "angular-animate": "~1.2"

    • "angular-touch": "~1.2"

    • "angular-sanitize": "~1.2"

    • "angular-bootstrap": "~0.11.0"

    • "angular-ui-utils": "~0.1.1"

    • "angular-ui-router": "~0.2.10"

    • "angular-gravatar": "~0.2.1"

You will also need the text editor called WebStorm, which you can download from http://www.jetbrains.com/webstorm/.

A modern browser will be very helpful too; we use Chrome, but feel free to use a browser of your choice. We recommend one of these: Safari, Firefox, Chrome, IE, Opera (all in their latest versions).

Who this book is for

If you're new to the world of SPA and want to explore the frameworks and tools available to start building rich SPA, this book is for you. However, if you already have some knowledge in this field, you might want to take a look at Chapter 7, Testing Angular SPA with Karma and Protractor, which is about testing a JavaScript MVC application, and Chapter 8, Deploying the Application to the Cloud, which is about continuous deployment using integrated cloud services.

You must have a basic to intermediate knowledge of HTML, CSS, and JavaScript to follow the examples in the book, but for some chapters, a slightly more advanced knowledge in web development/RESTful API and Node.js might be required. Don't worry about this; the examples will detail all the code and give you many links to interesting stuff.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

(function() {

  describe('Speakers Controller Tests', function() {
    // Initialize global variables
    var SpeakersController,
    scope,
    $httpBackend,
    $stateParams,
    $location;

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

  
beforeEach(function() {
    jasmine.addMatchers({
      toEqualData: function(util, customEqualityTesters) {
        return {
          compare: function(actual, expected)

Any command-line input or output is written as follows:

> require("./example.js")
Running through the example
{ greetings: 'Hello Node',
  sayHi: [Function] }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "On your right side, click on your account name right below Organizations."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Also you can check the book repository on GitHub at: https://github.com/newaeonweb/conference-api

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.