Node JS Assignment- 3
Basic Questions
- Use fs.readFile to read the content of sample.txt and log it.
- Use fs.writeFile to create a file output.txt with some text.
- Append “Hello Node.js” to an existing file using fs.appendFile.
- Rename a file old.txt to new.txt using fss.rename.
- Delete a file deleteMe.txt using fs.unlink.
- Create a directory named testDir using fs.mkdir.
- Read a file synchronously using fs.readFileSync and log its content.
- Write a file synchronously using fs.writeFileSync.
- Use fs.existsSync to check if a file exists.
- Watch a file watch.txt using fs.watch and log changes.
- Create a readable stream for a file and log “data received” on data event.
- Create a writable stream and write “Stream test” to a file.
- Convert a string “Node.js Buffer” into a buffer and log it.
- Decode a buffer into a string and print it.
- Print the length of a buffer created from “Hello World”.
- Create a basic HTTP server that returns “Hello, HTTP!”.
- Handle a GET request on / and return “Welcome Home”.
- Handle a POST request on /submit and log the received data.
- Parse query strings from a URL like /search?term=nodejs.
- Serve a static HTML file index.html using Node.js HTTP server.
Intermediate Questions
- Write a script that reads a JSON file asynchronously and logs parsed content.
- Write a script that appends current date and time to a log file every 5 seconds.
- Build a script that renames all files in a directory by adding a prefix new_.
- Create a directory uploads if it doesn’t exist, then save a file inside it.
- Compare reading a file synchronously vs asynchronously and log execution times.
- Create a file uploader simulation: read file.txt as a stream and write it to uploads/file.txt.
- Create a duplex stream that transforms text to uppercase and writes to another file.
- Use a transform stream to replace all occurrences of “foo” with “bar” in a file.
- Read a large file using streams and log data chunks size.
- Write a script that converts a buffer to hexadecimal and logs it.
- Create an HTTP server that handles GET /users and returns JSON.
- Create an HTTP server that handles POST /add-user and appends data to a file.
- Set custom headers (e.g., Content-Type) in your HTTP response.
- Handle 404 errors for undefined routes on an HTTP server.
- Serve static CSS and JS files along with an HTML file.
- Parse URL query parameters and return them in the HTTP response.
- Implement HTTP server logging: log method, URL, and timestamp for every request.
- Use fs.readdir to list all files in a directory and print them.
- Use a readable stream to count the number of lines in a text file.
- Write a script that deletes all files in a directory ending with .tmp.
Advanced Questions
- Build a file uploader server: accept POST request and save uploaded file using streams.
- Implement a script to watch a directory and automatically move new files to another folder.
- Create a HTTP server that supports GET, POST, PUT, DELETE for a JSON-based resource.
- Build a streaming download server: send a large video or file to clients in chunks.
- Implement a transform stream that encrypts file content using crypto module.
- Serve static content efficiently for HTML, CSS, JS, and images without using any frameworks.
- Compare synchronous vs asynchronous file operations under heavy load and log differences.
- Build a script to read multiple files in a directory asynchronously and merge their contents into a single file.
- Create a buffer manipulation program: read a file into buffer, modify specific bytes, and write back.
- Build a mini HTTP file server that handles range requests for partial file downloads.