Posts

Showing posts from April, 2019

Using React Router

What is React Router? React Router is a routing library built on top of react and is used to create routes for different links and giving access to them.So React Router is a very important module of React. So let's see how this works Installing React Router First you need to get react-router-dom(After installing React  with npx create-react-app ) npm install react-router-dom Now lets say we have 2 components users.js and home.js.(App.js as well if you installed React using create-react-app method). Users.js import React from 'react' class Users extends React.Component { render() { return <h1>Users</h1> } } export default Users Similar two for home.js and App.js Now import these 3 files to index.js file as below. import React from 'react' import ReactDOM from 'react-dom' import './index.css' import App from './App' import Users from './users' import Home from './home' ReactDOM.rend

Introduction to NODE.JS

Image
What is NODE.JS? Node.js is a JavaScript run-time.The language used is JavaScript.So Node.js is not a language or a framework or some library.So basically it's JavaScript running in your machine instead of browser which what was used to be done traditionally. It's been built on the V8 JavaScript engine(same engine Google Chrome is built on) .Node and V8 is mostly written in C++ language which is also very efficient and fast. So all this essentially means that we can use JavaScript as a server side language. Why  use NODE? Fast, efficient and highly scalable. Event driven,non-blocking I/O model.(will be explained down below) Popular in the industry. Same language on the front-end and back-end. NON-BLOCKING I/O used by NODE Node.js is non-blocking and asynchronous, It runs on a single thread using non-blocking I/O(Input/Output) calls.This single thread can support thousands of connections which are held in what called an event-loop.This method optimizes th

What is a Callback? - JavaScript

Image
Callback function is a function that is to be executed after another function has finished executing. So let's take a function that takes a function as an argument.This is possible because JS consider's functions as objects.So any function that is passed as an argument is called a Callback function.Now let's look at some examples. So why do we need Callbacks? You might already know that Java Script is an event driven language.This means that Java Script does not wait for responses from any event that takes time like I/O operations, Instead it keeps executing the code while listening to other events.This becomes a problem sometimes.Let's see why The output of this function will be 1,2 in order respectively as expected. No problem here.But what if the first function takes some time to execute?Like an API request that needs to wait for a response from the server.Let's look at an example related to this scenario.To do this we're going to use the function s