Node JS Assignment- 4

Basic Questions

  1. Create a simple HTTP server with two routes: / returns “Home Page” and /about returns “About Page”.
  2. Implement a route /hello that returns “Hello, Node.js”.
  3. Create a route /user/:id that prints “User ID: <id>”.
  4. Create a modular route file for /products returning a list of products.
  5. Handle undefined routes and return “404 Page Not Found”.
  6. Install https module and create a basic HTTPS server using a self-signed certificate.
  7. Print the URL parameters received in a route using req.params.
  8. Print query parameters using req.query.
  9. Connect to a local MySQL database using mysql2 module.
  10. Create a simple table users with columns id, name, email in MySQL.
  11. Insert a single user record into the users table using Node.js.
  12. Retrieve all records from users table and log them.
  13. Connect to a MongoDB database using the mongodb driver.
  14. Create a collection products in MongoDB and insert one document.
  15. Retrieve all documents from the products collection and log them.
  16. Create a modular route for /api/users and import it into your main server file.
  17. Use res.status to set HTTP response codes.
  18. Enforce HTTPS by redirecting HTTP requests to HTTPS in a Node.js server.
  19. Log the request method and URL for every incoming request.
  20. Handle a POST request on /login and print the received username.

Intermediate Questions

  1. Create dynamic routes /post/:postId/comment/:commentId and log both parameters.
  2. Organize all routes into separate files: /routes/home.js, /routes/user.js.
  3. Implement error handling middleware for undefined routes in modular routing.
  4. Create a MySQL connection pool using mysql2 module.
  5. Write a Node.js script to update a user’s email in MySQL by user ID.
  6. Delete a record from MySQL users table using Node.js.
  7. Write a Node.js function to query MongoDB products collection with a filter.
  8. Update a document in MongoDB collection using Node.js.
  9. Delete a document in MongoDB collection using Node.js.
  10. Create a route /search that accepts query parameters ?term=node and returns a filtered response.
  11. Build a secure API route that returns data only when accessed via HTTPS.
  12. Generate a self-signed SSL certificate and use it in an HTTPS server.
  13. Implement a route that returns JSON data for all users in MySQL.
  14. Implement a POST route that adds a new user record to MySQL from request body.
  15. Implement a GET route /users/:id that fetches a single user from MySQL.
  16. Create a route that returns all documents from MongoDB in JSON format.
  17. Implement a POST route /add-product to insert a new document into MongoDB.
  18. Create middleware that logs timestamp, route, and request method for every request.
  19. Implement URL validation for dynamic routes and return an error if invalid.
  20. Write a script to automatically close MySQL and MongoDB connections after queries.

Advanced Questions

  1. Build a secure API gateway that proxies requests to different microservices using HTTPS.
  2. Implement role-based authentication for API routes using MySQL user roles.
  3. Build a CRUD API for users with MySQL: Create, Read, Update, Delete endpoints.
  4. Build a CRUD API for products collection in MongoDB.
  5. Implement transaction handling in MySQL using mysql2 for multiple dependent queries.
  6. Create a route that handles both query parameters and URL parameters simultaneously.
  7. Implement HTTPS with proper SSL certificate validation and enforce redirect from HTTP.
  8. Build a route that aggregates data from both MySQL and MongoDB and returns combined results.
  9. Implement dynamic routing that loads route modules based on URL structure.
  10. Build a Node.js application that logs all database queries (MySQL and MongoDB) and monitors execution time for performance optimization.