Skip to content

Ayush4958/Js-Node.js

Repository files navigation

📘 Lecture 1 – Node.js File System Module (fs)

This lecture introduces basic file system operations in Node.js using the built-in fs module. Both asynchronous and synchronous methods are demonstrated.


📄 Topics Covered

✅ 1. Writing to Files

  • Asynchronously using fs.writeFile()
  • Synchronously using fs.writeFileSync()

✅ 2. Reading from Files

  • Asynchronously using fs.readFile()
  • Synchronously using fs.readFileSync()

✅ 3. Copying Files

  • Using fs.copyFileSync()

✅ 4. Deleting Files

  • Using fs.unlinkSync()

✅ 5. Getting File Info (Commented)

  • Using fs.statSync()

📘 Lecture 2 – Creating a Basic HTTP Server in Node.js

This lecture demonstrates how to create a basic HTTP server using Node.js' built-in http and url modules.

🔧 Key Concepts Used:

  • http.createServer() – Creating a web server

  • url.parse() – Parsing URL and extracting pathname and query parameters

  • fs.appendFile() – Logging requests to server.log

  • switch-case – Handling multiple routes

⚙️ What This Server Does:

  • Logs each incoming request with timestamp to server.log

  • Responds to different routes:

  • / → Home page response

  • /about?myname=YourName → About page with dynamic name

  • /contact → Contact page response

  • Any other path → 404 message


📘 Lecture 3 – Introduction to Express.js

In this lecture, you set up a basic web server using the popular Express.js framework for Node.js. It simplifies routing and handling HTTP requests.

🔧 Key Concepts Used:

  • express() – Initializes the express app

  • app.get() – Handles GET requests on specific routes

  • req.query – Accesses query parameters from the URL

  • res.send() – Sends a response to the client

🌐 What This Server Does:

Responds to:

  • / → Returns a static message from the Home page

  • /about?name=YourName → Returns a dynamic message from the About page using query param name


📘 Lecture 4 – RESTful API with Express, MongoDB (Mongoose) & MVC Architecture

In this lecture, the application is refactored into an MVC (Model-View-Controller) structure while connecting to a MongoDB database using Mongoose. The project includes custom middleware for logging and full CRUD operations for users.

🛠 Features Implemented

  • MVC Architecture

    • Models – Define database schema and interact with MongoDB.
    • Views – Render HTML responses.
    • Controllers – Contain route logic for handling requests and responses.
    • Routes – Organize API endpoints.
    • Middleware – Reusable functions (logging requests).
  • MongoDB Connection via Mongoose.

  • Request Logging Middleware – Logs request date, time, and path in logs.txt.

  • User CRUD API :-

    • Create, Read, Update, and Delete users.
    • HTML view for displaying users.

📌 Lecture-5: URL Shortener Project

In this lecture, I built a URL Shortener service using Node.js, Express.js, and MongoDB. The project allows you to:

  • Create short URLs from long links.
  • Redirect users from a short URL to the original URL.
  • Track analytics (click count + visit history with timestamps).

⚙️ Features

  1. Create Short URL
  2. Redirect to Original URL
  3. Get Analytics

🛠 Tech Stack

  • Node.js – Backend runtime
  • Express.js – Routing and middleware
  • MongoDB + Mongoose – Database and ORM
  • shortid – For generating unique short IDs

📘 Lecture 5 – URL Shortener with Authentication & Admin Authorization

This project builds a fully functional URL Shortener API with:

  • 🔐 JWT-based user authentication
  • 🧑‍💻 Role-based access (admin/user)
  • 🔗 Short URL generation
  • ↩️ Redirection to original URLs
  • 📈 Visit history + click analytics
  • 🧱 Built using clean MVC architecture

🚀 Features

✅ Register/Login Users can create accounts and receive a JWT token ✅ Auth Middleware Custom middleware validates JWT for protected routes ✅ URL Shortening Users can shorten any long URL ✅ Redirection Visiting short URL redirects to the original ✅ Analytics Tracks each visit with timestamp ✅ Admin Panel Admin can fetch all shortened URLs from all users ✅ Clean Architecture MVC: routes, controllers, models, middleware separated

🔐 Authentication & Authorization

  • JWT-based login: Upon login, users receive a token to access protected routes.
  • Roles:
    • user – Can shorten URLs, view own analytics
    • admin – Can view all URLs generated by any user
  • Custom Middleware:
    • authenticateUser – Verifies JWT -authorizeAdmin – Ensures only admin accesses admin-only routes

🧠 Tech Stack

Node JS

Express JS

MongoDB

JWT (jsonwebtoken)

shortid (for short URL generation)


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages