Book Image

AngularJS Web Application Development Blueprints

By : Vinci J Rufus
Book Image

AngularJS Web Application Development Blueprints

By: Vinci J Rufus

Overview of this book

If you are a web application developer interested in using AngularJS for a real-life project, then this book is for you. As a prerequisite, knowledge of JavaScript and HTML is expected, and a working knowledge of AngularJS is preferred.
Table of Contents (12 chapters)
11
Index

Building the server-side app


We'll start by building the server-side section of the app. We'll build a series of routes that will provide Create, Read, Update, Delete (CRUD) operations on our MongoDB database. We will expose these as REST APIs.

Let's write our models and custom routes into a separate route file to keep things clean.

Creating the Mongoose schemas

We first start by loading the mongoose library and establishing a connection to the angcms database. We add the following highlighted code in the angcms/app.js file:

var app = express();    
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/angcms');
var db = mongoose.connecetion;

For this application, we are going to need two schemas: the Pages schema and the Admin Users schema. Let's create these now.

We'll create a new folder named models, and create our page.js file with the following code in it:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;
    var Page = new Schema({
        title: String...