Book Image

Mastering JavaScript Single Page Application Development

Book Image

Mastering JavaScript Single Page Application Development

Overview of this book

Single-page web applications—or SPAs, as they are commonly referred to—are quickly becoming the de facto standard for web app development. The fact that a major part of the app runs inside a single web page makes it very interesting and appealing. Also, the accelerated growth of browser capabilities is pushing us closer to the day when all apps will run entirely in the browser. This book will take your JavaScript development skills to the next level by teaching you to create a single-page application within a full-stack JavaScript environment. Using only JavaScript, you can go from being a front-end developer to a full-stack application developer with relative ease. You will learn to cross the boundary from front-end development to server-side development through the use of JavaScript on both ends. Use your existing knowledge of JavaScript by learning to manage a JSON document data store with MongoDB, writing a JavaScript powered REST API with Node.js and Express, and designing a front-end powered by AngularJS. This book will teach you to leverage the MEAN stack to do everything from document database design, routing REST web API requests, data-binding within views, and adding authentication and security to building a full-fledged, complex, single-page web application. In addition to building a full-stack JavaScript app, you will learn to test it with JavaScript-powered testing tools such as Mocha, Karma, and Jasmine. Finally, you will learn about deployment and scaling so that you can launch your own apps into the real world.
Table of Contents (20 chapters)
Mastering JavaScript Single Page Application Development
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Free Chapter
1
Getting Organized with NPM, Bower, and Grunt
13
Testing with Mocha, Karma, and More

Incorporating MongoDB into the SPA


All this command-line stuff is great, but we need to start incorporating our MongoDB database into our SPA. In a future chapter, we will introduce the mongoose plugin for node, which will allow us to do data modeling, and which will perform a lot of heavy lifting for us.

For now, we're going to add a connection to MongoDB into our SPA in a simple way, which will highlight how to incorporate our database and display some dynamic data.

Adding the NPM modules

For this chapter, we need two modules to connect and easily access our MongoDB database inside our Express application. Those modules are mongodb and monk.

In your terminal, navigate to your giftapp directory and type the following (remember to lead with sudo if you're on a Mac or Linux):

npm install mongodb --save
...
npm install monk -save

The dependencies section of your package.json file should now look something like this:

"dependencies": { 
    "body-parser": "~1.13.2", 
    "cookie-parser...