A M.E.A.N Seminar – Who Am I – What is MEAN



A M.E.A.N Seminar – Who Am I – What is MEAN

1 0


css-mean-presentation


On Github ShamarKellman / css-mean-presentation

A M.E.A.N Seminar

Shamar Kellman

Computer Science Society

http://shamarkellman.github.io/css-mean-presentation

Who Am I

Shamar Kellman

Post-Graduate Student UWI

All-round developer

Research in Intelligent Virtual Agents (IVAs)

What is MEAN

  • MongoDB
  • Expres JS
  • Angular JS
  • Node JS

A single language across your entire stack increases productivity.

Starting with the database, we store information in a JSON like format. We can then write JSON queries on our Node server and send this directly to our front-end using Angular. This is especially useful when you have multiple developers working on a project together. Server-side code becomes more readable to front-end developers and vice versa. This makes everything a little more transparent and has been shown to greatly increase development time. The ease of development will become much more apparent once we start digging into examples and hopefully save you and your team some headaches in the future.

When To Be MEAN

  • Chat client
  • Real-time user updates (like Twitter feed)
  • RSS feed
  • Online shop
  • Polling app

When not to be MEAN

CPU intensive task

Who is being MEAN

  • Walmart - http://www.walmart.com
  • Yahoo - http://www.yahoo.com
  • Linkedin - https://www.linkedin.com
  • Paypal - https://www.paypal.com

For more see - http://nodejs.org/industry/

Walmart began using Node.js in 2012. They also stated that 53% of their Black Friday online traffic went to their Node servers with zero downtime.

Yahoo started experimenting with Node back in 2010. At first they just used it for small things like file uploads, and now they use Node to handle nearly 2 million requests per minute. They have noted increases in speed and a simpler development process.

LinkedIn began developing the server side of their mobile app entirely with Node. They were previously using Ruby, but since the switch they have seen huge increases in performance, ranging from 2 to 10 times faster.

PayPal has recently jumped onboard and began migrating some of their Java code to Node. They began experimenting with just their Account Overview page, but once they saw a 35% speed increase and half the amount of time spent on development, they started moving all sites to Node.js.

Node JS

  • The server-side platform in your MEAN application
  • Built on Google Chrome’s V8 JavaScript runtime
  • Single Threaded
  • Asynchronous
  • Event Driven

Node uses only one thread to handle all requests. it actually works out well given the asynchronous nature of Node.

Asynchronous events are executed independently of the main program’s “flow”.

Say, for example, a database query request comes in. Depending on how large the query is, it could take a couple of seconds to return anything. Since there is only one thread, it may seem that nothing else would be able to process while the query is executing.

NPM Package Mananger

One of the benefits of Node is its package manager, npm17. Like Ruby has RubyGems and PHP has Composer, Node has npm. npm comes bundled with Node and will let us pull in a number of packages to fulfill our needs.

Packages can extend functionality in Node and this package system is one thing that makes Node so powerful. The ability to have a set of code that you can reuse across all your projects is incredible and makes development that much easier.

Multiple packages can be brought together and intertwined to create a number of complex applications.

var http = require('http');

var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

server.listen(8000);

console.log("Server running at http://127.0.0.1:8000/");

Express JS

Express is a lightweight platform for building web apps using NodeJS.

a minimal and flexible node.js web application framework

Express hides a lot of the inner workings of Node, which allows you to dive into your application code and get things up and running a lot faster. It’s fairly easy to learn and still gives you a bit of flexibility with its structure. There is a reason it is currently the most popular framework for Node.

var express = require('express');
var app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');
});

var server = app.listen(3000, function () {
  var host = server.address().address;
  var port = server.address().port;

  console.log('Example app listening at http://%s:%s', host, port);
});

MongoDB

  • Open-source NoSQL database
  • Stores documents in JSON-style format
  • Schemaless
  • Document-oriented database
  • So multiple data-types

named from the word “humongous”

you define your data structure however you want.

You can easily take complex objects and insert them into your database using JSON, XML, BSON, or many other similar formats that are better suited to your application. You can even store PDF documents in certain document databases if the use case ever arises.

MySQL MongoDB Table Collection Row Document Column Field Joins Embedded documents, linking
{
    id: "1234",
    name: "holly",
    age: "400",
    type: "high-elf",
    address: {
        city: "rivendell",
        state: "middle-earth"
    }
}
db.users.insert({ 
	user_id: "bcd001", 
	age: 45, 
	status: "A"
})
db.users.find()
db.users.update(
	{ age: { $gt: 25 } },
	{ $set: { status: "C" } },
	{ multi: true }
)

Angular JS

  • Front-end framework (MVC)
  • Extends HTML
  • Two-way Data Binding
  • Dependency Injection
  • Directives & Templates
  • Scopes

Angular allows you to build your normal HTML application and then extend your markup to create dynamic components. If you’ve ever made a dynamic web page without Angular, you’ve probably noticed some of the common complications, such as data binding, form validation, DOM event handling, and much more. Angular introduces an all-in-one solution to these problems.

if you change data in your view (HTML files) or in your controller (JavaScript files), the data changes everywhere.

Dependency injection is a method by which we can give an object the dependencies that it requires to run.

JavaScript Primer

Variables and Data types

var myVar = 0;
var myInt = 0;
var myFloat = 2.5;
var myBoolean = true;
var myString = "This is a string";
var myArray = [1,2,3];
var myJSONObject = {
    myField : "Some value"
};
// Object instantiation using new
var myDate = new Date();client

Operators

var x = 4;
x = x + 1; // x is 5
y = x % 2; // y is 1
x++; // x is 6
x--; // x is 5
x += 3; // x is 8
var aString = "The value of x is " + x;

Conditions

if (x > 0) {
    // do something
} else {
    // do something else
}
var myString = "I have " + (x == 1 ? x + "thing" : x + "things");

Loops

for (var i = 0; i < myArray.length; i++) {
    console.log(myArray[i]);
}

while (x < 10) {
    console.log(x++);
}

Functions

function myIncrementFunction (x) {
    return x + 1;
}
myIncrementFunction(1000);

Require (Node.js)

var myLib = require("some-other-lib");

Before We Build

https://github.com/ShamarKellman/css-mean-contact-app

Installed Requirements

What we are using

  • express
  • Mongoose
  • Nodemon
  • Angular
  • UI-Router
  • Ng-Resource
  • Angular Material

Scaffolding the App

├── client
│   ├── css
│   ├── js
│   │   ├── controllers
│   │   └── services
│   ├── libs
│   └── views
├── config
├── node_modules
└── server
    └── models

				        

Package.json

npm init
				        

Let's Have Some Lunch

The Backend

The Frontend

Thank You

Sponsors: BrydenStokes

Special Thanks

Ariel

Kelsie

A M.E.A.N Seminar Shamar Kellman Computer Science Society http://shamarkellman.github.io/css-mean-presentation