Skip to main content

Posts

Showing posts from November, 2019

What is Command Design Pattern and how to implement it?

Intent - Encapsulate a request as an object thereby letting you parameterize with different requests , queue or log requests and support undoable options Now we will create two classes exit command will exit out of nodejs and create command will create new file. Now the interesting part of this post comes where we will define a class with help of which we will be able to run above defined commands , undo previously run command or redo previously undo command. At last with help of readline module we will take input from user of command which is to be executed.. Hope you like the post.Keep learning...

Making axios request using redux thunk react

How to integrate redux thunk with react? First run below command to get redux thunk installed Now add the redux thunk configuration to index.js file of your project Below is the sample folder structure to be followed.. Firstly lets code actions related to creating video on route /video/create Now at last lets make reducer function to handle actions dispatched Hope you like the post...

Cross-Site Scripting Attack and its prevention

What is Cross-Site Scripting Attack? XSS flaws occur whenever an application takes untrusted data and sends it to a web browser without proper validation or escaping. XSS allows attackers to execute scripts in the victims' browser, which can access any cookies, session tokens, or other sensitive information retained by the browser, or redirect user to malicious sites. How Cross-Site Scripting Attack is performed? There are two types of XSS flaws: Reflected XSS : The malicious data is echoed back by the server in an immediate response to an HTTP request from the victim. Stored XSS : The malicious data is stored on the server or on browser (using HTML5 local storage, for example), and later gets embedded in HTML page provided to the victim. Attack Prevention Input validation and sanitization : Input validation and data sanitization are the first line of defense against untrusted data. Apply white list validation wherever possible. Outp...

What is Factory Design Pattern and how can we implement it in Nodejs

First lets understand what Design Pattern means .In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations. Intent of Factory Pattern - Define an interface for creating an object but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses Now lets jump directly to code by creating basic Person class... Next we will create Shopper class extending Person class... Now lets create another class named Employee... After creating classes we will define function named userFactory which will be used to instantiate classes Employee and Shopper.. Now lets use userFactory function to create instances of Employee and Shopper classes... Hope you ...