Skip to content

Instantly share code, notes, and snippets.

@thamaraiselvam
Last active July 2, 2019 11:21
Show Gist options
  • Save thamaraiselvam/fcf8efa6520870e7a99d332337fab2f3 to your computer and use it in GitHub Desktop.
Save thamaraiselvam/fcf8efa6520870e7a99d332337fab2f3 to your computer and use it in GitHub Desktop.
This is my MEAN Stack cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

MEAN Stack Cheat-Sheet

Those who want to become a Full Stack Developer their first choice is MEAN Stack because it has a lot of scopes and easy to learn as well but preparing is hard so Here's a Cheat Sheet - Inspired by The Technical Interview Cheat Sheet.md

Cheating

This list is meant to be both a quick guide and reference for further research into these topics. It's basically a summary of important topics, there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

What the heck is MEAN Stack

  • MEAN is a user-friendly full-stack JavaScript framework ideal for building dynamic websites and applications.
  • One of the main benefits of the MEAN stack is that a single language, JavaScript, runs on every level of the application, making it an efficient and modern approach to web development.
  • MEAN is an acronym for MongoDB, ExpressJS, AngularJS and Node.js

MongoDB

humongous

MongoDB Introduction

  • What is MongoDB and where to be used ?

MongoDB is a type of NoSQL DB and used in the following applications such as unstable schema, need highly scalability and availability. Read More

  • Difference between NoSQL and SQL ?

MySQL Terms MongoDB Terms
database database
table collection
row document or BSON document
column field
index index
table joins embedded documents and linking
primary key Specify any unique column or column combination as the primary key. primary key In MongoDB, the primary key is automatically set to the _id field.
aggregation (e.g. group by) aggregation pipeline

Read more detailed comparison on MongoDB vs MySQL

Install MongoDB

  • How to Install MongoDB and Robo 3T?

Install MongoDB and Robo 3T (Robo 3T -formerly Robomongo is the free lightweight GUI for MongoDB enthusiasts)

  • How to Install the mongoose node module?

Mongoose is MongoDB driver which connects MongoDB and Node.JS Read Document

Work with Mongoose

  • Start with Schema?

Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.

 var mongoose = require('mongoose');
  var Schema = mongoose.Schema;

  var blogSchema = new Schema({
    title:  String,
    author: String,
    body:   String,
    comments: [{ body: String, date: Date }],
    date: { type: Date, default: Date.now },
    hidden: Boolean,
    meta: {
      votes: Number,
      favs:  Number
    }
  });
  • Creating a Model?

To use our schema definition, we need to convert our blogSchema into a Model we can work with. To do so, we pass it into mongoose.model(modelName, schema)

var Blog = mongoose.model('Blog', blogSchema);

Read More Mongoose guide

Basic CURD functions

Mongoose models provide several static helper functions for CRUD operations.

Save one or more Documents to the database

Shortcut for validating an array of documents and inserting them into MongoDB if they're all valid. This function is faster than .create() because it only sends one operation to the server, rather than one for each document.

Finds one document

Finds documents

Updates one document in the database without returning it.

Same as update(), except it does not support the multi or overwrite options.

Same as update(), except MongoDB will update all documents that match filter

Deletes the first document that matches conditions from the collection.

Deletes all of the documents that match conditions from the collection

Read more about Mongoose Queries

Aggregation

Aggregations are operations that process data records and return computed results

These are operations like sum, count, average, group etc where we need to generated grouped results out of collection. MongoDB exposes a pipeline based framework for aggregations, which looks something like below and Read more

Model.aggregrate([
   pipe1_operator : {...},
   pipe2_operator : {...},
   pipe3_operator : {...}
])
  • $group

Count the number of Users Belonging To A Particular Region

  • $match

$match acts as a where condition to filter out documents.

  • $project

$project is used to add columns dynamically to the collection and use it for further aggregation.

  • count

Count Number of User who belong to a certain region

  • distinct

Find all distinct regions

There are many more pipeline operators than dicussed above, which can be seen here

REST API

cat

What is REST API

  • A REST stands for Representational State Transfer is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data.

  • REST is a style of software architecture. As described in a dissertation by Roy Fielding, REST is an "architectural style" that basically exploits the existing technology and protocols of the Web.

HTTP Methods

RESTful APIs enable you to develop any kind of web application having all possible CRUD operations. REST guidelines suggest using a specific HTTP method on a specific type of call made to the server (though technically it is possible to violate this guideline, yet it is highly discouraged).

Use below-given information to find suitable HTTP method for the action performed by API.

  • HTTP GET

Use GET requests to retrieve resource representation/information only – and not to modify it in any way

  • HTTP POST

POST methods are used to create a new resource into the collection of resources.

  • HTTP PUT

Use PUT APIs primarily to update existing resource.

  • HTTP DELETE

As the name applies, DELETE APIs are used to delete resources.

  • HTTP PATCH

PATCH requests are to make partial update on a resource

Read more HTTP Methods

Express

faster

  • What is Express

Fast, unopinionated, minimalist web framework for node.

  • Installation

Follow this simple instructions by Express Community

  • Create Hello World REST API with Express

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

This app starts a server and listens on port 3000 for connections. The app responds with “Hello World!” for requests to the root URL (/) or route. Read Express Guide to know more about Express Routing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment