Understanding Linting, getting started with ESLint for Node.js development with IDE Visual Studio Code
Node.js , Javascript , Uncategorized / May 25, 2020

Node.js application developers usually come across the requirement to adhere to linting rules during the development phase. In this article we will understand the importance of following linting rules and how to set up ESLint with Node.js. We will also see how to easily identify and fix linting errors with Visual Studio Code.     Linting Linting is static code analysis, which helps to identify errors, coding style issues, insecure code, etc during the development phase. Linter is a tool that helps to identify lining errors while writing code. Linting is done during the phase of writing the code. Static code analysis is a method of debugging by examining source code before a program is run. Linting helps to improve code quality, provide better structure, speed up the overall development process by flagging potential errors early.   Linting JavaScript/TypeScript source code with Node.js Identifying linting errors in JavaScript code is done using the linting tool ESLint. If you are using TypeScript TSLint is used.   Linting Rules Linting rules are the rules which are enforced on the source code by the linter. For example, to enforce that the length of a single line of code not to exceed 140 characters max-len rule…

Modify wpDiscuz plugin, limit registered user to comment once and limit number of comments, in a post
Uncategorized / May 7, 2020

  Navigate to  wp-content/plugins/wpdiscuz/templates/comment/comment-form.php Find line

Put the following condition to limit the number of user comments to one and limit total comments.

Read more about the functions used here https://truetocode.com/disable-wordpress-comment-box-on-reaching-a-specific-number-of-comments-or-if-user-already-posted-a-comment/

Understanding serverless.yml file, properties with simple explanation, variables in serverless.yml – Serverless Framework and aws
AWS , Cloud , Uncategorized / April 23, 2020

Serverles.yml Property Description service Will have the properties which describe the service for which the YAML file is for, properties like name, arn… app Name of the app you create service for. App should be created in serverless and name can be found in serverless.com dashboard org Multiple organizations can be created in serverless and this property indicates the organization for which the service is created package Include/Exclude files or folders in the deployment package. Example,to exclude git folder,node_modules.. provider This Will have the properties for the cloud service provider. Details like name(eg:AWS),runtime(eg:Node.js), region(eg:Ohio),and others like timeout,stage(dev,prod..) and memory custom Will have custom variables for services like base, params, role… functions Will have functions in the service. Functions can have name, handler, environment variables, description… resources We will have the resources used by the service, like DynamoDB tables, lambda… output Variable for refactoring. It can be used in other serverless.yml files. This Can be used along with different app/stage/region.Example: ${output:appname:stagename:regionname:my-service.var-key}         Variables in Serverless Variables can be used in YAML file in different ways, the orange highlighted text indicates the various  ways Variables are added using interpolation, variable values are referenced using ${}.     ${self:provider.stage} –…

AppSync/GraphQL : Pagination on DynamoDB data: Curser based pagination
AWS , Cloud , Uncategorized / April 14, 2020

What is AppSync? AWS AppSync helps you create a flexible API to securely access, manipulate, and combine data from one or more data sources.AppSync uses GraphQL. AppSync can be used along with Amazon services like Lambda, DynamoDB, etc.. What is GraphQL? GraphQL is a language for APIs that enables you to query and manipulate data easily through an intuitive and flexible syntax. GraphQL provides a syntax to describe data requirements and interactions, allowing you to ask for exactly what you need and get back predictable results. This article aims at providing strategy on how to query data in the DynamoDB table with sorting and pagination. The pagination strategy used is called cursor-based pagination. Curser based pagination helps to avoid the problems of limit-offset pagination. Shifting of data on insertion and on deletion occurs while paginating in a limit-offset way, this is not ideal for real-time data. Whats is curser based pagination? Cursor-based pagination works using a pointer to a specific item in the dataset. By using this strategy major pitfalls of limit-offset pagination can be avoided.     Achieving pagination on DynamoDB data with AppSync/GraphQL Consider a case where we have an Entity Employees and each employee has multiple  Tasks. It’s a…

AWS: Create an Lambda function that returns a Presigned URL to upload an image to a S3 bucket,Node.js
AWS , Node.js , Cloud , Uncategorized / April 7, 2020

This tutorial aims at providing basic steps required to create a Lambda which will provide a Presigned URL that can be used to upload an object to the AWS S3 bucket. Upload is tested here with Postman. What is s3 ? Amazon S3 or Amazon Simple Storage Service is a service offered by Amazon Web Services that provides object storage. An object consists of a file and optionally any metadata that describes that file. S3 helps to store the objects in buckets, which are more or less like file folders.   What is  presigned URL for s3? A presigned URL gives you access to the object identified in the URL, provided that the creator of the presigned URL has permissions to access that object. That is, if you receive a presigned URL to upload an object, you can upload the object only if the creator of the presigned URL has the necessary permissions to upload that object.   What is ARN? Amazon Resource Names (ARNs)  are identifiers used to uniquely identify AWS resources       Step 1: Create a bucket to store image. Go to services->s3->create bucket Give a name like fortestinglambda Provide public access to the bucket for now and leave…

Create a Lambda and modify and deploy it using cloud9 IDE, work with npm and add Node.js packages to Lambda – Beginner’s guide
AWS , Cloud , Uncategorized / April 1, 2020

In this tutorial, we will learn to  Create an AWS Lambda function with Node.js as the Runtime environment. Import the function into AWS Cloud9(Cloud9 IDE is an Online IDE). Initialize npm, add dependency moment.js and deploy it.   Step 1 – Create a Lambda. Goto services->Lambda and click Create function Choose Author from scratch, Node.js as Runtime, provide a function name and click Create function

The above code will be provided by default. By default, the aws-sdk is available in Lambda functions and you can import it using

        Step 1 – Create an environment and  Import lambda into cloud9 IDE Cloud9 is a AWS online IDE provided by AWS. To access cloud9 move to services->Cloud9.Click on the Create environment button, provide name and description, choose default options and click on the Create environment button.   The IDE interface will look like this.   To import the Lambda function, move to AWS resource and import your remote function.               Step3 – Install Node.js dependency, moment.js. To install Node.js dependency, terminal access is required. To access terminal, go to window->New terminal and access your function folder using 

Do npm…

How to read data from AWS DynamoDB tables using AWS Lambda. get, scan and query methods(Node.js).
AWS , Cloud , Uncategorized / March 30, 2020

This tutorial aims at explaining how to read data from the AWS DynamoDB table. AWS SDK has a class AWS.DynamoDB.DocumentClient, which has methods scan, get and query, that are used to read data from the AWS DynamoDB table.  Documentation on various methods provided by the class is available from the following link AWS.DynamoDB.DocumentClient – Documentation.   Table structure primary partition key – name sort key – age table name – testTable This may not be the ideal table structure but here we use it just as an example.     step 1: Executing the query to get all data from a table – scan method. The scan method is used to  read every item in the table and returns all the data in the table. Filters can be also applied First of all, we create an object scanningPrams which has all the params including the table name, required to scan the DynamoDB table. Simple params to get 10 items from a table “testTable“, would look like this.

The output will have the following structure

The output will have three properties:  Items will have the queried items, ScannedCount will have the number of items evaluated before any scanFilter is…

Advanced interview questions for web application server-side/ back-end developers, Node.js – Part1

Here are some interview questions that Lead backend developers, with experience of  3+ years, usually face during interviews. QUESTIONS What are authentication and authorization? What is OAuth? What are API gateways and advantages of using them? Which is the best place to store session_ids or access_tokens. What are the different types of client-side storages and their differences?  What are middlewares? What is CORS(Cross-origin resource sharing), what is the importance and how to handle CORS? Describe microservices, web services, and APIs? How to validate requests while building REST APIs and why it is important? Explain the difference between SQL databases and NoSQL databases? Explain callbacks We have foreach loop and in each, we will have asynchronous operations. How to handle this case? ANSWERS Authentication is about verifying user identity and authorization is about checking whether a resource can be accessed. Authorization is not about user identity, it is about whether a requester can be granted permission to access a resource. Authentication is about verifying a user’s identity. Authentication and authorization are used together for providing security to a system. Here is a very useful article to learn the differences between authentication and authorization. This article also explains how these two are…

Steps for creating an EC2 instance and setting up Git remote repository, with detailed descriptions.
AWS , Cloud , Uncategorized / March 26, 2020

Here are the steps to create an EC2(Amazon Elastic Compute Cloud), set up your Git remote repository in EC2 and connect to the remote repo from your local machine. Some explanations are provided for better understanding. AWS Elastic Compute Service(EC2) is IaaS(Infrastructure as a Service).   PART 1 – Creating and connecting to AWS EC2 Virtual Machine instance.   STEP 1  – Go to AWS console. STEP 2 – goto services, click on EC2 and create a virtual machine by clicking on the launch instance button. EC2 is IAAS just like a compute engine in google. STEP 3 – Amazon has provided templates for engines with different OS and processor combinations. Choose one option and move forward. Select according to your needs and click on launch. STEP 4 – On clicking the launch button amazon asks to create or choose a  key-value pair. A key pair consists of a public key that AWS stores, and a private key file that you store. You have to provide the private key name. A .pem file with the key will be downloaded which is the private key. Public-key cryptography, or asymmetric cryptography, is a cryptographic system that uses pairs of keys: public keys which may be disseminated…

Sass Part 1 – An introduction, Sass variables and Nesting rules, and properties in Sass
css , SASS , Uncategorized / December 15, 2019

Hey, folks! Welcome to the  Sass series. The aim of this series is to give a general idea of what Sass is, why it is beneficial and what are the key properties of Sass which makes it beneficial. Becoming an expert is in Sass can be achieved through rigorous practice and hands-on experience in real projects. This series will give you guys a platform to start with. WHAT YOU WILL LEARN Sass is a CSS preprocessor Sass has two syntaxes Sass syntax allows variables, mixins, nesting rules and properties, function Variables declared using $ , 7 data types are supported,and scope of variable. Interpolation for selector or property names using {} Parent selector using & and nesting     Sass or syntactically awesome stylesheet Sass is a CSS preprocessor that will generate CSS files for your project. “A CSS preprocessor is a program that will generate CSS  from a syntax supported by it.” Sass generates CSS files from .sass or .scss files that have their own syntax. Sass allows using features like variables,functions, mixins, etc that CSS files do not allow(CSS now supports variables but the usage is a bit different and browser support is limited).   SASS is originally written in Ruby. A…

Share this page in social media platforms