Node JS Assignment- 3

Basic Questions

  1. Use fs.readFile to read the content of sample.txt and log it.
  2. Use fs.writeFile to create a file output.txt with some text.
  3. Append “Hello Node.js” to an existing file using fs.appendFile.
  4. Rename a file old.txt to new.txt using fss.rename.
  5. Delete a file deleteMe.txt using fs.unlink.
  6. Create a directory named testDir using fs.mkdir.
  7. Read a file synchronously using fs.readFileSync and log its content.
  8. Write a file synchronously using fs.writeFileSync.
  9. Use fs.existsSync to check if a file exists.
  10. Watch a file watch.txt using fs.watch and log changes.
  11. Create a readable stream for a file and log “data received” on data event.
  12. Create a writable stream and write “Stream test” to a file.
  13. Convert a string “Node.js Buffer” into a buffer and log it.
  14. Decode a buffer into a string and print it.
  15. Print the length of a buffer created from “Hello World”.
  16. Create a basic HTTP server that returns “Hello, HTTP!”.
  17. Handle a GET request on / and return “Welcome Home”.
  18. Handle a POST request on /submit and log the received data.
  19. Parse query strings from a URL like /search?term=nodejs.
  20. Serve a static HTML file index.html using Node.js HTTP server.

Intermediate Questions

  1. Write a script that reads a JSON file asynchronously and logs parsed content.
  2. Write a script that appends current date and time to a log file every 5 seconds.
  3. Build a script that renames all files in a directory by adding a prefix new_.
  4. Create a directory uploads if it doesn’t exist, then save a file inside it.
  5. Compare reading a file synchronously vs asynchronously and log execution times.
  6. Create a file uploader simulation: read file.txt as a stream and write it to uploads/file.txt.
  7. Create a duplex stream that transforms text to uppercase and writes to another file.
  8. Use a transform stream to replace all occurrences of “foo” with “bar” in a file.
  9. Read a large file using streams and log data chunks size.
  10. Write a script that converts a buffer to hexadecimal and logs it.
  11. Create an HTTP server that handles GET /users and returns JSON.
  12. Create an HTTP server that handles POST /add-user and appends data to a file.
  13. Set custom headers (e.g., Content-Type) in your HTTP response.
  14. Handle 404 errors for undefined routes on an HTTP server.
  15. Serve static CSS and JS files along with an HTML file.
  16. Parse URL query parameters and return them in the HTTP response.
  17. Implement HTTP server logging: log method, URL, and timestamp for every request.
  18. Use fs.readdir to list all files in a directory and print them.
  19. Use a readable stream to count the number of lines in a text file.
  20. Write a script that deletes all files in a directory ending with .tmp.

  Advanced Questions

  1. Build a file uploader server: accept POST request and save uploaded file using streams.
  2. Implement a script to watch a directory and automatically move new files to another folder.
  3. Create a HTTP server that supports GET, POST, PUT, DELETE for a JSON-based resource.
  4. Build a streaming download server: send a large video or file to clients in chunks.
  5. Implement a transform stream that encrypts file content using crypto module.
  6. Serve static content efficiently for HTML, CSS, JS, and images without using any frameworks.
  7. Compare synchronous vs asynchronous file operations under heavy load and log differences.
  8. Build a script to read multiple files in a directory asynchronously and merge their contents into a single file.
  9. Create a buffer manipulation program: read a file into buffer, modify specific bytes, and write back.
  10. Build a mini HTTP file server that handles range requests for partial file downloads.