This lecture introduces basic file system operations in Node.js using the built-in fs module. Both asynchronous and synchronous methods are demonstrated.
- Asynchronously using
fs.writeFile() - Synchronously using
fs.writeFileSync()
- Asynchronously using
fs.readFile() - Synchronously using
fs.readFileSync()
- Using
fs.copyFileSync()
- Using
fs.unlinkSync()
- Using
fs.statSync()
This lecture demonstrates how to create a basic HTTP server using Node.js' built-in http and url modules.
-
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
-
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
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.
-
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
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
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.
-
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.
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).
- Create Short URL
- Redirect to Original URL
- Get Analytics
- Node.js – Backend runtime
- Express.js – Routing and middleware
- MongoDB + Mongoose – Database and ORM
- shortid – For generating unique short IDs
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
✅ 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
- 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
Node JS
Express JS
MongoDB
JWT (jsonwebtoken)
shortid (for short URL generation)