Skip to main content

Posts

Showing posts from December, 2019

Javascript Higher Order Function:Reduce, Map, Filter, Sort Examples

Reduce Example 1: Example 2:  Map Filter Sort Combined Method

Looping: For, ForEach, ForIn

For Loop Example: ForEach Loop Example: For In Loop Examples:

MERN

The MERN stack is a popular stack of technologies for building a modern single-page application. The MERN stack consists of the following technologies: MongoDB : A document-based open source database. Express : A web application framework for Node.js. React : A JavaScript front-end library for building user interfaces. Node.js : JavaScript run-time environment that executes JavaScript code outside of a browser (such as a server). It is also common to use  Mongoose , which is a simple, schema-based solution to model application data.

TypeScript Programming Language

ES6 -> let (if multiple ref. change), cons (if no change) - Use ES6 and ts # TS: - all features can be written in compile in js and run. - TS is not loosly types. It's strict. Example: let abc: String;      abc: 634 Error: type 634 is not assignable to type 'String'. Example:  let abc: any; // (data type can be used in abc variable. dont use any all time). Important: - npm i typescript g //(to install typescript) - tsc - h //(help typescript) - tsc abc.ts //(to run typescript. it now creates abc.js file . equivalent file code) - tsc -v //(check version) - ng --version (angular cli info-> angular cli version, node, os) - overall angular application, we use angular cli. angular cli use webpack (like task runner, module bundler). -ng equivalent to angular 2, 4, 5, 6 # Task runner -> small task like minify, file concatenate. # Web pack -> modules bundle and make file

Javascript: Frontend - AngularJS

# FrontEnd Technologies: # Web (Internet) - Html, css framework (bootstrap, material design-> component based) Angular 2 - Single page application (fast). - Web application or website that interacts with the user by dynamically rewritting the current page rather than loading entire new pages from a server. - Can do asynchronous jobs. # Tools: - Typescript - VS code # MVVW (Model View ViewModel Pattern) -> two-way data binding - In angular, the controller (the C in MVC) is replaced by ViewModel (the VM in MVVM). # Typescript Programming Language Typescript (.ts) is imp in angular 2. - supersetup js - strictly typed program - can do class based oop - future programming language. - security maintain (TS code compile and run in js) - JS with additional features. # Data Binding - Controller and Views synchronize. Types: 1. Event -  eg: click, onClick, change 2. Property - eg: hide, show 3. 2-way binding - Reflect in view if changes in model- controller

REST, API, RESTFUL API

REST, API, REST API (separation of concern) # REST   - (Representational State Transfer) is a software architecture style that defines a set of constraints to be used for creating web services. -  REST  Technology is generally preferred to the more robust SOAP (Simple Object Access Protocol) technology because REST leverages less bandwidth, making it more suitable for internet usage. REST is: Architecture (engineering) Protocol(HTTP)  Stateless protocol (eg: http protocol) #Rest Architecture design principal: 1.  Client Server Architecture (express js api -> Restful api) 2. Http protocol and method 3. Http verbs (method used for data interchange->get, post, put, delete) 2. Stateless 3. JSON data interchange (from data -> json, error, response, json) 4. Communication (same protocol) #REST Architecture - Data needs to fetch in Get request. - Data needs to insert in Post request. - Data needs to update in Put request. - Data needs to delete in De

JavaScript Conference: How function is called?

Javascript is running from washing machine to robot. It is no longer a scripting language. JS is created in 1994. # Javascript types Functional (closure) Object-oriented (class, object, polymorphism, inheritance, abstraction) # Language types: Interpreted language and compile language # Function can be called in 4 ways: 1. Function Invocation Pattern Example: function add(num1, num2){       console.log(this); } var res = add (8, 9); console.log(res); Output: Global object 2. Call function as new operator i.e Construction Invocation Pattern Example: function add(num1, num2){       this.foo = num1;       console.log(this); } var res = new add (8, 9); console.log(res); Output: add {foo: 8} add {foo: 8} 3. Call function as an object ( Method Invocation Pattern ) eg. abc.name 4. Call function indirectly using method ( Indirect Invocation Pattern ) Example: function add(num1, num2){       console.log(this); } var Cat{      nam

VS Code

1. cmd+shift+p (search feature in vs code) 2. run command (code .) (it will be installed and run code from terminal) # VS CODE - code, debug, extension, extension icon - jshint - prettier-code formatter - beautify - vscode - icons - ESLint - TSLint

NodeJS: Request and Respose Objects

# req Objects - req - req.body, req.queries, req.validationerrors - res.headers, req.users, req.file, req.assert - req.params, req.checkbody #res Objects - res.send, res.end, res.json, res.render, res.status, res.sendStatus # - .limit(4) //limit only upto 4 docs - skips(3) //skip first 3 docs - exe //query build and then execute, it is also callback function of mongoose. - sort({_id: -1}) //for decending order - populate('userId') //populating data inside the reference.

Database : MongoDB

# SQL (structured query language) / RDBMS (Relational DBMS) - Table- row (table format) (tabular design) - table-table relation (primary, foreign key) - define schema (schema is collection of DB objects associated with one particular DB username. Logical structure of data.) - insert, fetch, update, remove (CURD) -> Create, Update, Retrieve, Delete - Example: MySql, MS-SQL (includes defined property (eg. id, name)) # Distributed DBMS (Non- RDBMS) - Collection (table )-> documents (but no relation) - No Schema - Documents (JSON Objects) within collection - is highly scalable and can includes various property (eg. id, name, address..), can define field - Example: No SQL type (MongoDB) and nested object - MongoDB is a general-purpose, doc-based, distributed DB built for modern app developers and for the cloud era. Global cloud DB on AWS, Azure. -Mongodb automatically set id (object id) unique key (primary key) Important Command (MongoDB): mongo (sh

Javascript: Object to Array and Array to Object

Output: Final Array [ { mango: 1 }, { apple: 2 }, { banana: 3 }, { orange: 1 }, { watermelon: 1 }, { papaya: 1 } ] Output: Final Object { mango: 1, apple: 2, banana: 3, orange: 1, watermelon: 1, papaya: 1 }

NodeJS: Command

Framework - Node JS is run time environment. Non-blocking, asynchronous (done through event looping). No wait for previous result, next event handle. (Event loop helps for asynchronous. callback will be in queue, this cycle is called event loop.) - Events and handling events (mongoose->connection, every events triggers something. eg. click event triggers. event based architecture -> we can take anything as events.) - Node CLI (terminal -> node(>) REPL(Read, Evaluate, Print, Loop).) eg: >4+4 >8 - With OSI (Open System Interconnection) Model, we can work Example: Source:  https://www.geeksforgeeks.org/layers-of-osi-model/ - Software Development Architecture (Engineering)  - MVC (Model View Controller) web outline -The framework provides important available material, outline to build application. - API framework (Application Programming Interface) # Desktop Framework - Electron, NW.js, APPJS, Meteor, Proton Native #Mobile Framework - PhoneGa

NodeJS: Express JS

Express JS (MVC) framework/architecture for nodejs (web) express js as Rest API (get, post, put, delete - req. http method). Htpp interaction communication (http req -> request response cycle) middleware input data, process, meaningful output (Web App) npm install express -- save Note: - An object is equivalent to Javascript. - NodeJS is equivalent to the callback. - ExpressJS is equivalent to Middleware. Creating Server in NodeJS and http module (Client Server Communication) 1. mkdir firstapp 2. cd firstapp 3. npm init 4. create app.js Explanation (app.js): - http module injection - createServer method (callback function use -> req, res) - After client and server connection, server will listen and client will request. (req is always http req.object and res or 2nd argyment is always http response object.) - req.end (end the request and listen the server (1st arg-> port, 2nd arg-> host and 3rd arg-> callback function.)) - If er

Github Tutorial

GitHub brings together the world's largest community of developers to discover, share, and build better software. Delivered through software as a service(SAAS) business model 2008 by linus (Owner: Microsoft)  #Create New Repository in Github New Repository Add Repository Name and description Public / Private, initialize this repo with Read Me Create repository create a new repository on the command line echo "#test" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/sinuna/test.git git push -u origin master …or push an existing repository from the command line git remote add origin https://github.com/sinuna/firstRepository.git git push -u origin master …or import code from another repository You can initialize this repository with code from a Subversion, Mercurial, or TFS project. Initialize Repo $ git init Clone Repo $ git clone https://github.com