JavaScript & MEAN Stack Notes
1. MEAN Stack Development Framework
The MEAN Stack stands for MongoDB, Express.js, Angular, and Node.js. It is a full-stack
JavaScript framework used to build dynamic web applications:
- MongoDB: NoSQL database that stores data in flexible, JSON-like documents.
- Express.js: Web application framework for Node.js, used to build RESTful APIs.
- Angular: Frontend framework developed by Google for building dynamic SPAs (Single Page
Applications).
- Node.js: JavaScript runtime environment that executes code on the server side.
The MEAN stack allows the use of JavaScript throughout the entire development
process—client-side, server-side, and database querying—making development faster and more
consistent.
Architecture Flow:
1. Client (Angular) sends a request.
2. Server (Express + Node.js) handles routing and logic.
3. Database (MongoDB) stores and retrieves data.
4. Response flows back through Express to Angular.
2. Setting Up Node.js and Angular
Node.js Setup:
1. Download and install Node.js from nodejs.org.
2. Verify installation:
node -v
npm -v
JavaScript & MEAN Stack Notes
3. Create a project folder and initialize:
mkdir myproject
cd myproject
npm init -y
Angular Setup:
1. Install Angular CLI globally:
npm install -g @angular/cli
2. Create a new Angular project:
ng new my-angular-app
3. Serve the project:
cd my-angular-app
ng serve
3. JavaScript Variables and Data Types
Variable Declaration: Use var, let, or const.
- var is function-scoped, can be redeclared.
- let and const are block-scoped. const cannot be reassigned.
Example:
let x = 10;
const y = "Hello";
Data Types:
- Primitive: Number, String, Boolean, Null, Undefined, Symbol
- Non-Primitive: Object, Array, Function
JavaScript & MEAN Stack Notes
Example:
let num = 42;
let str = "JS";
let isReady = true;
let arr = [1, 2, 3];
let obj = { name: "Alice", age: 30 };
4. JavaScript Operators
- Arithmetic: +, -, *, /, %, ++, --
- Comparison: ==, ===, !=, !==, <, >, <=, >=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=, /=
- Bitwise, Ternary, and Type Operators
Example:
let a = 5;
let b = 3;
let max = (a > b) ? a : b;
5. Control Structures
If Statement:
if (a > b) {
console.log("A is greater");
}
JavaScript & MEAN Stack Notes
Switch Statement:
switch(day) {
case "Mon": console.log("Start of week"); break;
default: console.log("Unknown day");
Loops:
for (let i = 0; i < 5; i++) console.log(i);
let j = 0;
while (j < 5) {
console.log(j);
j++;
let k = 0;
do {
console.log(k);
k++;
} while (k < 5);
6. Functions (Parameter Passing & Return Values)
Functions are defined using the function keyword. They can take parameters and return values.
Example:
function add(a, b) {
JavaScript & MEAN Stack Notes
return a + b;
let sum = add(5, 3); // sum = 8
Note: Objects/arrays are passed by reference.
7. Objects (with Examples)
Objects are key-value pairs.
let person = {
name: "Alice",
age: 30
};
console.log(person.name); // "Alice"
Objects can hold methods:
let car = {
make: "Toyota",
honk: function() {
return "Beep!";
};
8. Strings (Definition, Methods, Programs)
Strings are sequences of characters.
JavaScript & MEAN Stack Notes
Common methods:
length, toUpperCase(), toLowerCase(), substring(), indexOf(), replace()
Example:
let str = "Hello, World!";
console.log(str.toUpperCase()); // "HELLO, WORLD!"
Program:
let greeting = "Hello";
let name = "John";
console.log(greeting + " " + name); // "Hello John"
9. Arrays (with Methods and Examples)
Arrays store multiple values.
let colors = ["red", "green", "blue"];
colors.push("yellow"); // ["red", "green", "blue", "yellow"]
Useful methods:
push(), pop(), shift(), unshift(), splice(), slice(), forEach(), map()
Program:
let nums = [1, 2, 3];
let doubled = nums.map(n => n * 2); // [2, 4, 6]
10. Error Handling (try, catch, finally)
JavaScript & MEAN Stack Notes
JavaScript uses try-catch-finally for error handling.
Example:
try {
throw new Error("Something went wrong");
} catch (err) {
console.error(err.message);
} finally {
console.log("Cleanup done");
11. NPM Command-Line Options (Table 3.1)
Common NPM Commands:
- npm install
- npm update
- npm uninstall
- npm init
- npm run
Options:
--save: adds to dependencies
--global: install globally
Example:
npm install express --save
JavaScript & MEAN Stack Notes
12. package.json Directives (Table 3.2)
Key directives:
- name, version, description, main, scripts, dependencies, devDependencies
Example:
"name": "myapp",
"version": "1.0.0",
"scripts": {
"start": "node app.js"
13. Writing Data to Console (with Examples)
Use console.log() to print data.
Other methods:
- console.error()
- console.warn()
- console.table()
- console.dir()
Example:
console.log("Hello, World!");
console.error("This is an error");