Create a node server with the following requirements: Use the dotenv package to manage your development environment variables. PORT should be 3000 HOST should be localhost Endpoints /dotted Only GET requests are allowed. This endpoint will respond with the HTML content type. This endpoint will take two required query parameters: word1 and word2. The endpoint will take the two words and create a string that is the two words separated by enough “.” characters to make the length of the string 30. For example if word1 is “turtle” and word2 is “153” the output should be: turtle.....................153 The response body should be the string wrapped in a tag. /fizzBuzz Only GET requests are allowed. This endpoint will respond with the HTML content type. This endpoint will take two required query parameters: start and end. The endpoint will iterate from start to end and for each number it will: Show “Fizz” if the number is divisible by 3. Show “Buzz” if the number is divisible by 5. Show “FizzBuzz” if the number is divisible by both 3 and 5. Show the number if it is not divisible by 3 or 5. Each iteration output should be on a new line. For example, if start is 9 and end is 16, the output would look like this: Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 The response body should be the string wrapped in a tag. /gradeStats Only GET requests are allowed. This endpoint will respond with the JSON content type. This endpoint will take an array parameter, grades, that requires at least one value. The program should return JSON containing the minimum and maximum values in the array as well as the average. For example, if the grades entered are 88, 73, 97, 87 the endpoint should return:{"average":"86.25","minimum":"73","maximum":"97"} /rectangle Only GET requests are allowed. This endpoint will respond with the JSON content type. This endpoint will take two required parameters: length and width. This endpoint should return JSON containing the perimeter and area. For example, if length is 2 and width is 4, the endpoint should return:    {"area":"8","perimeter":"12"}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Create a node server with the following requirements:

  1. Use the dotenv package to manage your development environment variables.
    1. PORT should be 3000
    2. HOST should be localhost
  2. Endpoints
    1. /dotted
      1. Only GET requests are allowed.
      2. This endpoint will respond with the HTML content type.
      3. This endpoint will take two required query parameters: word1 and word2.
      4. The endpoint will take the two words and create a string that is the two words separated by enough “.” characters to make the length of the string 30.
        1. For example if word1 is “turtle” and word2 is “153” the output should be: turtle.....................153
      5. The response body should be the string wrapped in a <pre> tag.
    2. /fizzBuzz
      1. Only GET requests are allowed.
      2. This endpoint will respond with the HTML content type.
      3. This endpoint will take two required query parameters: start and end.
      4. The endpoint will iterate from start to end and for each number it will:
        1. Show “Fizz” if the number is divisible by 3.
        2. Show “Buzz” if the number is divisible by 5.
        3. Show “FizzBuzz” if the number is divisible by both 3 and 5.
        4. Show the number if it is not divisible by 3 or 5.
        5. Each iteration output should be on a new line.
        6. For example, if start is 9 and end is 16, the output would look like this:
          1. Fizz
            Buzz
            11
            Fizz
            13
            14
            FizzBuzz
            16
        7. The response body should be the string wrapped in a <pre> tag.
    3. /gradeStats
      1. Only GET requests are allowed.
      2. This endpoint will respond with the JSON content type.
      3. This endpoint will take an array parameter, grades, that requires at least one value.
      4. The program should return JSON containing the minimum and maximum values in the array as well as the average.
      5. For example, if the grades entered are 88, 73, 97, 87 the endpoint should return:{"average":"86.25","minimum":"73","maximum":"97"}
    4. /rectangle
      1. Only GET requests are allowed.
      2. This endpoint will respond with the JSON content type.
      3. This endpoint will take two required parameters: length and width.
      4. This endpoint should return JSON containing the perimeter and area.
      5. For example, if length is 2 and width is 4, the endpoint should return:    {"area":"8","perimeter":"12"}
Expert Solution
Step 1: Here is an implement the node server with the given requirements using express

Here is an example code to implement the node server with the given requirements using express:

 

CODE in javascript:

 

const express = require("express");
const dotenv = require("dotenv");

dotenv.config();

const app = express();
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || "localhost";

app.get("/dotted", (req, res) => {
  const word1 = req.query.word1;
  const word2 = req.query.word2;
  const dots = ".".repeat(30 - word1.length - word2.length);
  const response = `<pre>${word1}${dots}${word2}</pre>`;
  res.contentType("text/html");
  res.send(response);
});

app.get("/fizzBuzz", (req, res) => {
  const start = parseInt(req.query.start);
  const end = parseInt(req.query.end);
  let response = "";
  for (let i = start; i <= end; i++) {
    if (i % 3 === 0 && i % 5 === 0) {
      response += "FizzBuzz\n";
    } else if (i % 3 === 0) {
      response += "Fizz\n";
    } else if (i % 5 === 0) {
      response += "Buzz\n";
    } else {
      response += `${i}\n`;
    }
  }
  res.contentType("text/html");
  res.send(`<pre>${response}</pre>`);
});

app.get("/gradeStats", (req, res) => {
  const grades = req.query.grades.map(grade => parseInt(grade));
  const average = grades.reduce((a, b) => a + b, 0) / grades.length;
  const minimum = Math.min(...grades);
  const maximum = Math.max(...grades);
  const response = { average: average.toFixed(2), minimum, maximum };
  res.contentType("application/json");
  res.send(response);
});

app.get("/rectangle", (req, res) => {
  const length = parseInt(req.query.length);
  const width = parseInt(req.query.width);
  const area = length * width;
  const perimeter = 2 * (length + width);
  const response = { area, perimeter };
  res.contentType("application/json");
  res.send(response);
});

app.listen(PORT, HOST, () => {
  console.log(`Server running at http://${HOST}:${PORT}`);
});

 

 

 

OR

OR

OR

 

 

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Form and its Elements
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education