Node JS Assignment- 4
Basic Questions
- Create a simple HTTP server with two routes: / returns “Home Page” and /about returns “About Page”.
- Implement a route /hello that returns “Hello, Node.js”.
- Create a route /user/:id that prints “User ID: <id>”.
- Create a modular route file for /products returning a list of products.
- Handle undefined routes and return “404 Page Not Found”.
- Install https module and create a basic HTTPS server using a self-signed certificate.
- Print the URL parameters received in a route using req.params.
- Print query parameters using req.query.
- Connect to a local MySQL database using mysql2 module.
- Create a simple table users with columns id, name, email in MySQL.
- Insert a single user record into the users table using Node.js.
- Retrieve all records from users table and log them.
- Connect to a MongoDB database using the mongodb driver.
- Create a collection products in MongoDB and insert one document.
- Retrieve all documents from the products collection and log them.
- Create a modular route for /api/users and import it into your main server file.
- Use res.status to set HTTP response codes.
- Enforce HTTPS by redirecting HTTP requests to HTTPS in a Node.js server.
- Log the request method and URL for every incoming request.
- Handle a POST request on /login and print the received username.
Intermediate Questions
- Create dynamic routes /post/:postId/comment/:commentId and log both parameters.
- Organize all routes into separate files: /routes/home.js, /routes/user.js.
- Implement error handling middleware for undefined routes in modular routing.
- Create a MySQL connection pool using mysql2 module.
- Write a Node.js script to update a user’s email in MySQL by user ID.
- Delete a record from MySQL users table using Node.js.
- Write a Node.js function to query MongoDB products collection with a filter.
- Update a document in MongoDB collection using Node.js.
- Delete a document in MongoDB collection using Node.js.
- Create a route /search that accepts query parameters ?term=node and returns a filtered response.
- Build a secure API route that returns data only when accessed via HTTPS.
- Generate a self-signed SSL certificate and use it in an HTTPS server.
- Implement a route that returns JSON data for all users in MySQL.
- Implement a POST route that adds a new user record to MySQL from request body.
- Implement a GET route /users/:id that fetches a single user from MySQL.
- Create a route that returns all documents from MongoDB in JSON format.
- Implement a POST route /add-product to insert a new document into MongoDB.
- Create middleware that logs timestamp, route, and request method for every request.
- Implement URL validation for dynamic routes and return an error if invalid.
- Write a script to automatically close MySQL and MongoDB connections after queries.
Advanced Questions
- Build a secure API gateway that proxies requests to different microservices using HTTPS.
- Implement role-based authentication for API routes using MySQL user roles.
- Build a CRUD API for users with MySQL: Create, Read, Update, Delete endpoints.
- Build a CRUD API for products collection in MongoDB.
- Implement transaction handling in MySQL using mysql2 for multiple dependent queries.
- Create a route that handles both query parameters and URL parameters simultaneously.
- Implement HTTPS with proper SSL certificate validation and enforce redirect from HTTP.
- Build a route that aggregates data from both MySQL and MongoDB and returns combined results.
- Implement dynamic routing that loads route modules based on URL structure.
- Build a Node.js application that logs all database queries (MySQL and MongoDB) and monitors execution time for performance optimization.