Posts

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