Posts

Showing posts from 2023

How to Use VIM Editor in CLI

Image
VIM is most popular editor which Developer's generally require to use while Development, Let's see how we can use it: VIM Editor - Education Funda Open a File: ~ vim fileName.ext  To save and exit the Vim editor, you can use the following commands: :wq  This command saves the changes to the file and exits Vim. It is equivalent to “write and quit”. :w : This command saves the changes to the file, but remains in Vim. You can continue editing or use other commands to manipulate the file. :q! : This command exits Vim without saving changes. It is equivalent to “quit bang” and discards any unsaved modifications. Additional Tips To enter command mode, press the Esc key. To switch between insert mode and command mode, use Esc to exit insert mode and return to command mode. Save and exit a file: :wq Save a file without exiting: :w Exit Vim without saving changes: :q! Rename a file and save changes: :w new_filename.txt Save and exit multiple files: :wqa Remember to use these commands

Rate Limiting in Node with Express

Image
Rate Limiting is Most Common Practice to Limit The Incoming Request of API's  Rate Limit in Node.js - Education Funda Let's see how we can achieve it easily in Node with Express framework: You need to install rate limit package via ~$ npm i express-rate-limit . import * as RateLimit from 'express-rate-limit' ; const env = process . env . NODE_ENV || 'dev' ; const rateLimitRequest = Number ( process . env . RATE_LIMIT_TIME ) || 15 ; const rateLimitTime = Number ( process . env . RATE_LIMIT_REQUEST ) || 100 ; export default () => { if ( env === 'production' ) { return new RateLimit ({ windowMs: rateLimitTime * 60 * 1000 , // 15 minutes max: rateLimitRequest , // limit each IP to 30 requests per windowMs delayMs: 0 , handler: 'Rate limt exceeded, please try again later some time.' , }); } return new RateLimit ({ windowMs: 5 * 60 * 1000 , // 5 minutes max: 3000 , //

Postman Collection APIs to Swagger Docs

Image
Being an back-end developer we generally works with APIs, for storing the APIs mostly developers are using the Postman, So in this blog will discuss how to covert postman collection APIs to swagger APIs documentation. Express Js Project Convert Postman Collection APIs to Swagger Docs Step 1: You should have proper APIs postman collection for your project. Step 2: Install swagger ui in your node project via ~ npm i swagger-ui-express . Step 3: Put below code in your Routes index file OR app.js wherever you maintained your express routes as per your requirements: Here you also need to create 1 json file for storing the details of your APIs docs just like we create swagger-output.json . import express from "express" ; import swaggerUi from "swagger-ui-express" ; const swaggerDocument = JSON . parse ( await readFile ( new URL ( "../../../../swagger-output.json" , import .meta. url )) ); const router = express . Router (); // adding swagger docs

AWS CloudWatch Check Logs of Lambdas

Image
While working in Microservices concept, you generally need to check CloudWatch logs in deep to identify the errors and debugging your code. So let's see how we can check logs insight of particular lambda. AWS CloudWatch - Education Funda Recent Logs For recent logs you can directly go into Lambda inside it monitor section. Lambda Logs Monitor Filter Logs Old Logs Insights Go down in Monitor logs and go to Recent Invocations section, on top right sight you can see 3 dots for action: Go in Logs Insight for Lambda Next screen will open like below in which you can run query and after that in graph you can select specific date and time logs very easily. Thanks for reading this blog, I hope it is helpful for you, please share your feedback in comments section guys. <> Happy Coding </> 💻

Connect with Oracle DB in Node JS

Image
Let's see how can we connect with oracle db in node js project or lambda Oracle DB - Education Funda First step is to install oracle db package with below command: ~ npm i  oracledb Let's see the code for connecting with oracle db for lambda handler: const oracledb = require ( "oracledb" ); oracledb . outFormat = oracledb . OUT_FORMAT_OBJECT ; exports . handler = async ( event , context , callback ) => { let connection ; const uatConnObj = { user : "db_user_name" , password : "db_pass" , connectString : "ip:port/db" , poolMax : 1 , poolMin : 0 , poolIncrement : 10 , }; const prodConnObj = { user : "db_user_name" , password : "db_pass" , connectString : "ip:port/db" , poolMax : 1 , poolMin : 0 , poolIncrement : 10 , }; try { await oracledb . createPool ( prodConnObj ); let dbPool = oracledb . getPool ();

MongoDB Helpful Queries

Image
While doing the development everyones know that no one can remember all of the queries and commands. So in the blog I am covering most used Mongo DB queries. Mongo DB Queries By Education Funda Mongo DB Queries For Studio 3T and In Your Code Fetch Queries: db . getCollection ( "collectionName" ). find ( { FILTER_COLUMN_NAME : 'VALUE' }, { PROJECTION_COLUMN_NAME_1 : 1 , PROJECTION_COLUMN_NAME_2 : 1 } ) Get Duplicates Records db . getCollection ( "collectionName" ). aggregate ([ { "$group" : { "_id" : "$DUP_COL_NAME" , "count" : { "$sum" : 1 } } }, { "$match" : { "_id" : { "$ne" : null } , "count" : { "$gt" : 1 } } }, { "$project" : { "DUP_COL_NAME" : "$_id" , "_id" : 0 } } ]) Count Query db . getCollection ( "collectionName" ). countDocuments ( { FILTER_COL_1 : 

How To Create S3 Bucket In AWS And Connect With Node JS

Image
a AWS S3 Bucket - Education Funda Create Policy Add ARN Create User as Allow and Create Role ? Add s3-user-policy as permission Now go into user and create access and secret key

Python Convert List of Strings/Numbers to Array

Image
When we are working many times we have a requirements where we need to convert list of data from excel or anything to arrays so that we can filter data from DB with in array conditions. Python Programming Step 1: You should have Python installed in your system to run it. Step 2: Create a Directory and Open that directory in VS Code Editor. Step 3: Create 1 file any-name.py. Step 4: Put below codes in created file: with open ( 'list.txt' , 'r' ) as f : content = f . read (). split ( " \n " ) for i in range ( len ( content )): contentLine = content [ i ] if len ( contentLine ) < 10 : print ( contentLine ) content [ i ] = contentLine . rjust ( 10 , '0' ) with open ( 'array.txt' , 'w' ) as f : f . write ( '[" {} "]' . format ( '", "' . join ( content ))) Step 5: Now create 2 files list.txt and array.txt . Step 6: Put some list of any da

MongoDB Mongoose Use Lookup Guide

Image
In This Blog We Will See Complete Guide For Using Joins With Lookup in Mongoose MongoDB Mongoose - Education Funda Simply in MongoDB Mongoose we can use Aggregate Query with $ lookup to get data basis upon JOINS. such as below: await MainModel . aggregate ([ { $match : { "COLUMN_NAME" : value } }, { $lookup : { from : 'relation_collection_name' , localField : 'relation_collection_primary_key' , foreignField : 'this_table_foreign_key' , as : 'ALIASING' } } ]); With above query new column added with ALIASING in which relation collection data will also come. To get data in Object format instead of Array we can use $unwind like below: await MainModel . aggregate ([ { $match : { "COLUMN_NAME" : value } }, { $lookup : { from : 'relation_collection_name' ,

Create and Deploy AWS SAM Application

Image
How To Create and Deploy Your First Lambda Function on AWS Serverless Application Modal AWS SAM - Education Funda Create Your SAM Application Software Requirements: AWS CLI ( Reference Link ) SAM CLI ( Reference Link ) Docker ( Reference Link ) AWS Serverless Architecture - Education Funda Now All Will Happen With Command Line Interface Now open Terminal and Go to your directory in which you want to create your project. $ sam init  #hit enter this command ~ This will appear 2 option, 1 AWS Quick Start and 2 Custom Template For making things simple you can 1 at moment. ~ Now you need to select template, at moment you can select Hello World Example. ~ Now it will ask for programming language Python by default and you can select other as well such as Node.js, Java, etc. ~ Now you can choose ZIP option. ~ Now it will ask starter template, you can select anyone from that Hello World Example. ~ X-Ray tracing you can enable so select Y. ~ Enable Cloud Watch now with select Y. ~ Now it ask

Deploy Angular Build With Express JS Project

Image
Deploy Angular Build in Node JS (Express JS) Server Mean Stack - Education Funda Firstly Create Angular Production Ready Build: ~ ng build (run in command line when directory is projectFolder). ~ Compress using Brotli compression the resources using the following command for i in dist/*/*; do brotli $i; done Deployment Check Angular Build: You can get a preview of your application using the ng serve --prod command that starts a local HTTP server such that the application with production files is accessible using http://localhost:4200. This is not safe to use for production usage. For a production usage, you have to deploy all the files from the dist folder in the HTTP server of your choice. Node JS/Express JS Server File Changes: //enabling CORS app . use ( cors ()); app . use ( express . static ( path . resolve ( './public' ))); //api v1 base route set app . use ( '/api/v1' , router ); //angular front site app . use ( express . static ( path . resolve ( './public/a

Install Free SSL For Nginx Server with Ubuntu 20.X

Image
If you want to install free SSL for your domain then you are on right blog. In this blog I will explain you how you can configure free SSL certificate with Ubuntu Server. By Education Funda Step 1: Go and connect to your server with ROOT user either with SSH or Putty. Step 2: Now enter this command $ sudo apt-get update Step 3: Now enter this command $  sudo snap install core; sudo snap refresh core Step 4: Now enter this command $  sudo apt-get remove certbot Step 5: Now enter this command $  sudo snap install --classic certbot Step 6: Now enter this command $  sudo ln -s /snap/bin/certbot /usr/bin/certbot Step 7: Now enter this command $  sudo certbot --nginx Now in Step 7 after enter it will ask your domain name and email address please enter details carefully here then That's it, You have done it, Yeah 💪 It will be valid up-to 3 months. For any question or feedback please write into comments section, I hope this blog will be helpful for you if Yes then please share it

JavaScript Logical Output Based Interview Questions

Image
You mostly seen in JavaScript interviews there interviewers must asks output based questions in which candidate stuck mostly so here in this blog I'm telling you most commonly asked output based JavaScript interview questions. By Education Funda Most Commonly Asked JavaScript Output Based Questions Question: 1 function sum(){      let a = 8;      const b=2;      var c=a+b; } console.log(a) // Reference error: a is not defined console.log(b) // Reference error: a is not defined console.log(c) // Reference error: a is not defined sum() console.log(a) // Reference error: a is not defined console.log(b) // Reference error: b is not defined console.log(c) //Output: undefined ---------------------------------------------------------------------------- Question: 2 let arr=[1,2,3,4,5]; console.log(arr[2], arr.length); //Output: 3 5 arr.length=0; console.log(arr[2], arr.length); //Output: undefined 0 Note:  As we can see in above code 1st questions is so easy but second is bit tricky one

Run Node JS Project Without Port in URL

Image
We can remove PORT from URL in Node JS project from server configuration files So we have mainly two types of server base: Nginx Apache For both we generally have /etc/nginx/default OR /etc/apache2/default file . So you have to edit it manually which you can do via below steps: 1. Firstly go into nginx/apache2 directory  Then, Run command: ~ sudo nano default configuration file will open in edited mode from which you can edit now server { listen 80 default_server; listen [::]:80 default_server; location { proxy_pass http://yourdomain.com:3000;      #try_files comment this line manually via adding # } } Restart your server via nginx/apache2 ~ sudo service nginx restart ~ sudo service apache2 restart That's it now check http://yourdomain.com this will also work same. Happy Coding !!