Skip to content

Instantly share code, notes, and snippets.

View Gaurav8757's full-sized avatar
🏠
Working from home

Gaurav Kumar Gaurav8757

🏠
Working from home
View GitHub Profile
@Gaurav8757
Gaurav8757 / redis.md
Last active May 31, 2026 10:16
Advanced Redis or redisio

Redis Methods:

Single key-value pairs set/get karne ke liye use hota hai.

-- set/get => data store in string format

-- hset/hget/hgetall:

  • Data store in Object format
  • Used in store userProfile to get data fast not db calls and if any update invalidate data.
@Gaurav8757
Gaurav8757 / Logout.md
Created May 31, 2026 09:07
How many ways to secure logout

Approach 1: Client-side logout (Simple)

  • Token delete karo
  • Cookie clear karo
  • Small projects me common hai.

Approach 2: Token Blacklisting (Enterprise)

Logout ke time:

@Gaurav8757
Gaurav8757 / otpTimerWithRedisTTL.js
Created May 31, 2026 08:57
OTP Verify | OTP Timer With Redis TTL
// Best approach:
// OTP send API se initial TTL le lo.
// Frontend me local countdown chalao.
// Jab page refresh ho ya component remount ho tab TTL API hit karo.
// Backend API
// send otp
app.post("/otp/send", async (req, res) => {
@Gaurav8757
Gaurav8757 / sshkeys.md
Last active May 28, 2026 10:35
ssh keys create use and install github, pm2, nginx, ssl, tls, node.js, mysql, pm2 service

1. Create SSH key pair (Private & Public keys) using "ssh-keygen" on your local system.

1. Open Terminal

2. Run the following command:

ssh-keygen -t ed25519 -C "your_email@example.com"

If your system doesn’t support ed25519, use RSA:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
@Gaurav8757
Gaurav8757 / Sequelize.md
Last active May 23, 2026 10:23
How to Use Sequelize ORM with Node.js | Broad Database Support: Works with Postgres, MySQL, MariaDB, SQLite, SQL Server, Oracle, Amazon Redshift, and Snowflake.

To use Sequelize ORM with Node.js for database operations including models, migrations, associations, queries, and transactions with PostgreSQL, MySQL, or SQLite.

It provides a clean API for database operations with support for migrations, associations, and transactions.

Installation

# Sequelize core

npm install sequelize
@Gaurav8757
Gaurav8757 / Redis.md
Created May 19, 2026 13:52
Foundation of Redis

Foundation OF Redis

Database Library “new keyword” Reason
MongoDB Mongoose ❌ Required नहीं mongoose.connect() खुद client बना देता है
MongoDB Custom Mongoose ✔ Required const customMongoose = new mongoose.Mongoose(); आपको नया independent client चाहिए होता है
Redis ioredis ✔ Required const redis = new Redis(); // <- NEW keyword required Redis client एक class instance होता है
Redis redis (legacy) ✔ Required वही reason — class instance
@Gaurav8757
Gaurav8757 / prisma.md
Last active April 5, 2026 05:51
All Installations setup here..

See Examples: -url: https://www.prisma.io/docs/prisma-orm/quickstart/postgresql

DIRECT_URL to create table (Migration)

DIRECT_URL="postgres://USER:PASSWORD@db.prisma.io:5432/postgres?sslmode=require" 

DATABASE_URL to query with db (Queries)!

DATABASE_URL="postgres://USER:PASSWORD@pooled.db.prisma.io:5432/postgres?sslmode=require"
@Gaurav8757
Gaurav8757 / mysql.sql
Created March 29, 2026 07:55
If you forgot root password of mysql workbench
1. Open CMD as administrator
2. taskkill /F /IM mysqld.exe >> ERROR: The process "mysqld.exe" not found.
Step_1 >> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
Step_2 >> mysqld --initialize-insecure // Initialize(fresh setup)
Step_3 >> mysqld --install MySQL80 // service installed
Step_4 >> net start MySQL80 // start services
Step_5 >> mysql -u root // login to mysql
Step_6 >> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123'; // Password set karo
Step_7 >>
@Gaurav8757
Gaurav8757 / urlencoded.js
Last active March 28, 2026 12:13
How express.urlencoded || express.raw() Works?
// 1. converts the incoming data into a JavaScript object and makes it accessible through req.body
// 2. { extended: true } is set, it supports >> nested objects and arrays << using the qs library.
// 3. It only parses requests with Content-Type: application/x-www-form-urlencoded, ignoring other data formats.
app.use(express.urlencoded({ extended: true }))
app.get('/login', (req, res) => {
res.send('<form method=POST action=/login><input type=text name=username><input type=number name=age><input type=submit></form>')
})
express.raw() function: It parses incoming request payloads into a >> Buffer << and is based on body-parser.