Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using JavaScript 2.Writing N Files Synchronously [25%] Allowed Node.js API Functions: fs.writeFile() Input: Integer n (0 < n < 100) Output: n Files Create a

using JavaScript

2.Writing N Files Synchronously [25%]

  • Allowed Node.js API Functions: fs.writeFile()
  • Input: Integer n (0 < n < 100)
  • Output: n Files

Create a program that synchronously write n files 01-output.txt up to 99-output.txt to a subdirectory output. Each file should contain the text "Data-2". After each successful fs.writeFile() print a message to console with the filename. After all n files are finished, print an additional message Writing Complete Run the script a few times, the filenames printed should always be in order.

3.

Personal Hosts File [20%]

  • Allowed Node.js API Functions: fs.readFile(), fs.writeFile(), dns.resolve()

  • Input: File: domains.txt

    • Contains one valid domain name on each line
    • All supplied domains will only have a single IP addresses associated with it.
  • Output: File hosts.txt

Write a program that reads from a file domains.txt residing in a directory input. It contains a list of valid domains one on each line, resolve each domain found to IP addresses, and save the results into a file hosts.txt residing in a directory output. The output format should be ip_address, a tab character (\t), domain_name.

The order in which the results appear does not matter. (But see Ungraded Additional Question)

Sample Output:

149.4.199.190 venus.cs.qc.cuny.edu
149.4.211.163 cs.qc.cuny.edu

4.

Four synchronous tasks [20%]

  • Allowed Node.js API Functions: fs.readFile(), zlib.inflate(), dns.resolve(), fs.writeFile()
  • Input: domain.deflated
  • Output: File: ip_address.txt

Write a program that:

  1. Reads domain.deflated (Use {encoding:null} ),
  2. Decompresses the contents using zlib.inflate(), covert the resulting buffer to a string using .toString("utf8") the decompressed data will be a valid domain that resolves to a single IP address.
  3. Using dns.resolve() convert the domain into an IP address.
  4. Remove the array wrapper and write the IP address to a file ip_address.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions