Skip to content

MoARABY/nodejs-advanced-topics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 

Repository files navigation

NodeJS-advanced-topics

Redis Cache Middleware πŸ“

This part integrates Redis as a caching layer for API responses in a Node.js / Express application.
The goal is to reduce database load and improve performance by serving cached data when available.

πŸš€ Features

  • Caches API responses using Redis.
  • Reuses cached data if available instead of hitting the database.
  • Supports dynamic keys based on request params.
  • Easy to plug into any Express route.

πŸ“¦ Redis Installation

  • redis not available for direct installation on windows so we should use Docker
  • docker pull redis -or-
  • docker run -d --name redis -p 6379:6379 redis:latest
  • docker exec -it my-redis redis-cli (run redis cli)

inside project file

  • npm install redis
  • then start coding which mentioned in the "cache" branch

project usage

  • in this project we use redis for
  • 1- cache while request all products
  • 2- cache while request one product
  • 3- cache deleted when add,update,delete products

Scheduler with node-cron ⏰

This part integrates node-cron into the project to handle scheduled background tasks

πŸš€ Features

  • Task scheduling using node-cron.
  • Runs scheduled jobs inside your Node.js/Express app.
  • Uses standard cron expressions.
  • Easy to plug into any Express route.

πŸ“¦ node-cron Installation

  • npm install node-cron

β”‚ β”‚ β”‚ β”‚ β”‚

β”‚ β”‚ β”‚ β”‚ └─── Day of the week (0 - 7) (Sunday = 0 or 7)

β”‚ β”‚ β”‚ └──────── Month (1 - 12)

β”‚ β”‚ └───────────── Day of the month (1 - 31)

β”‚ └────────────────── Hour (0 - 23)

└─────────────────────── Minute (0 - 59)

project usage

  • we use cron job to work every 1 hour on products docs see if any product has quantity less than 5
  • write product data inside 'lastQProducts' file

LLM integration and embeddings

This part integrates OpenAI API and groq to generate embeddings for your application data. The goal is to transform text into high-dimensional vectors that can be used for semantic search, recommendations, and AI-powered features.

πŸš€ Features

  • asking questations to AI from your app
  • Generates vector embeddings using OpenAI models.
  • Stores embeddings for efficient semantic search instead of simple keyword search.
  • Easy to integrate into any Node.js / Express project.

πŸ“¦ llm Installation

  • Install the OpenAI package : npm i openai
  • Install groq sdk : npm i groq-sdk

project usage

  • first start with basic askAI controller
  • then working with embedding model to advanced AI-Query

About

Advanced APIs topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors