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
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 on Github for everyone. Please feel free to rise a issue or PR if anything missing or any correction required.
MongoDB is a type of NoSQL DB and used in the following applications such as unstable schema, need highly scalability and availability. Read More
Read more detailed comparison on MongoDB vs MySQL
Install MongoDB and Robo 3T (Robo 3T -formerly Robomongo is the free lightweight GUI for MongoDB enthusiasts)
Mongoose is MongoDB driver which connects MongoDB and Node.JS Read Document
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
}
});
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);
Mongoose models provide several static helper functions for CRUD operations.#### create()
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
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 : {...}
])
Count the number of Users Belonging To A Particular Region
$match acts as a where condition to filter out documents.
$project is used to add columns dynamically to the collection and use it for further aggregation.
Count Number of User who belong to a certain region
Find all distinct regions
There are many more pipeline operators than dicussed above, which can be seen here
All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.
Being built on Google Chrome’s V8 JavaScript Engine, Node.js library is very fast in code execution.
Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server
Node.js applications never buffer any data. These applications simply output the data in chunks.
Following are the areas where Node.js is proving itself as a perfect technology partner.
*** It is not advisable to use Node.js for CPU intensive applications ***
NPM is a package manager for the JavaScript programming language. It is the default package manager for Node.js and it is the world’s largest Software Registry. It contains more than one million packages.
Simply download the Installer directly from the nodejs.org web site or follow the instructions for platform specific.
Such as Debian, Ubuntu, Linux mint and Raspbian
sudo apt-get install nodejs npm
pacman -S nodejs npm
brew install node
Simply download the Windows Installer directly from the nodejs.org web site.
Single threaded processes contain the execution of instructions in a single sequence. In other words, one command is processed at a time. Read more about single thread vs multi thread
The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.
Since most modern kernels are multi-threaded, they can handle multiple operations executing in the background. When one of these operations completes, the kernel tells Node.js so that the appropriate callback may be added to the poll queue to eventually be executed
Read the following links to learn more about Event Loop
What the heck is the event loop anyway? by Philip Roberts - JSConf EU
Visualisation tool for event loop
A JavaScript engine is a program or interpreter which reads our JavaScript code, produces machine code, and finally runs the machine code. It is landed in JavaScript runtimes like web browsers, Node.js, or even Java Runtime Environment (JRE). Like any other interpreters, its job is to read and execute code.
JavaScript runtime is another software. It uses JavaScript Engine and provides some additional functionalities as needed. The most common example of the runtime is the web browser. Probably the second most widely used runtime is Node.js.
ECMAScript(ES) is a scripting-language specification standardized by Ecma International. It was created to standardize JavaScript and new standards is released on every year.
Refer express for hello world program.
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.
Use GET requests to retrieve resource representation/information only – and not to modify it in any way
POST methods are used to create a new resource into the collection of resources.
Use PUT APIs primarily to update an existing resource.
As the name applies, DELETE APIs are used to delete resources.
PATCH requests are to make partial update on a resource
Read more HTTP Methods
The fast, unopinionated, minimalist web framework for node.
Follow this simple instruction by Express Community
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
Note: Always Refer Angular Docs for a detailed explanation
Angular is a TypeScript-based open-source web application framework for building mobile and desktop web applications
Angular requires Node.js version 10.9.0 or later. To install node.js, go to Install Node
npm install -g @angular/cli
that’s it you have installed Angular on your machine.
The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications. You can use the tool directly in a command shell.
Enter the following to list commands or options for a given command (such as generate) with a short description
ng help
ng generate --help
Know more about Angular CLI
Now it is time to create your first Angular application.
Use the new
command to create a new application.
ng new my-first-project
and enter into created application cd my-first-project
Use serve
to run the application.
ng serve
In your browser, open http://localhost:4200/ to see the new app run. When you use the ng serve command to build an app and serve it locally, the server automatically rebuilds the app and reloads the page when you change any of the source files.
Angular is a platform and framework for building client applications in HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your apps.
The basic building blocks of an Angular application are NgModules, which provide a compilation context for components. NgModules collect related code into functional sets; an Angular app is defined by a set of NgModules. An app always has at least a root module that enables bootstrapping and typically has many more feature modules
Learn more about Angular Modules
Components define views, which are sets of screen elements that Angular can choose among and modify according to your program logic and data. Every component consists of a selector, template, and style. Template and style can be inline or separate files.
Learn more about Angular components
Components use services, which provide specific functionality not directly related to views. Service providers can be injected into components as dependencies, making your code modular, reusable, and efficient.
You can have sharable methods and data into services.
Learn more about Angular Services
Angular Routing helps to control navigation paths of an application.
which helps to retain the application state as well.
Learn more about Angular Routings
Angular templates are dynamic. When Angular renders them, it transforms the DOM according to the instructions given by directives. A directive is a class with a @Directive() decorator.
A component is technically a directive. However, components are so distinctive and central to Angular applications that Angular defines the @Component() decorator, which extends the @Directive() decorator with template-oriented features
Structural directives alter layout by adding, removing, and replacing elements in the DOM. For Example *ngFor, *ngIf, *ngSwitch and so on.
Attribute directives alter the appearance or behavior of an existing element. In templates they look like regular HTML attributes, hence the name. For example [style.color], [color], [(ngModel)] and so on.
After creating a component/directive by calling its constructor, Angular calls the lifecycle hook methods in the following sequence at specific moments:
Learn More about Angular Lifecycle
You can see that your angular application has dozens of files and folders. lets see what is the purpose of them.
the e2e folder has all unit test files and you should write unit testing inside this dir only.
This folder contains all our application codes such as components, services and so on.
This folder is for asset files such as images, fonts.
This is for environment configurations such as Devopment mode, Production mode.
All browser compatibility stuff lies here.
This style file is common for entire angular application. if you want to define a style for the whole app, you can do here, such as theming styles.
The unit testing configuration file
Package.json contains all npm and script related stuff
This file contains meta related to the angular application
Compiler Configuration for TypeScript
Linter Configurations
EditorConfig helps maintain consistent coding styles for multiple developers
Sharing Data Between Angular Components - Four Methods
Angular pipes let you declare display-value transformations in your template HTML. A class with the @Pipe decorator defines a function that transforms input values to output values for display in a view.
<!-- Default format: output 'Jun 15, 2015'-->
<p>Today is {{today | date}}</p>
<!-- fullDate format: output 'Monday, June 15, 2015'-->
<p>The date is {{today | date:'fullDate'}}</p>
<!-- shortTime format: output '9:43 AM'-->
<p>The time is {{today | date:'shortTime'}}</p>
One way data binding from Component to View
One way data binding from View to Component
Two-way data binding between Component to View
That’s it. These are the most important topics of MEAN Stack, Please feel free to rise a issue or PR if anything is missing or any correction required.
Now go and Practice.
#angular #node-js #javascript #mongodb #web-development