Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Multi-part question - please use a), b), c), d) to identify your responses. Given a server.js file that uses express (you do not need to

Multi-part question - please use a), b), c), d) to identify your responses.

Given a server.js file that uses express (you do not need to write the express imports), write code to respond to the routes below as specified in each description. NOTE: all callback functions must be written in the new ES6 "Arrow Function"syntax:

a) Write route "/test"that can capture all verbs (GET, PUT, POST, DELETE, etc.) and responds with a 200 status code, making sure to also "end" the response without sending anything back.

b) Write "GET" route for a variable "num" ie: /employee/5 and responds with a JSON formatted string: {employeeNum: num} where num is the value passed in the url.(HINT: req.______.num).

c)Assuming our server.js is using the "path" module, write a "GET" route "/employeeDocs/training" and send the file "training.pdf" (located at the root of your application folder), causing the user's browser to prompt them to download it. (HINT: do not forget to include __dirname in your solution).

d) Write "GET" route "/employees" . This route will support optional queries:

"/employees?pay=PAY" which responds with a JSON formatted string: {message: PAY } (wherePAY is the value passed in the url). (HINT: req._____.pay).

"/employees?position=POSITION" which responds with a JSON formatted string: {message: POSITION} (where POSITIONis the value passed in the url). (HINT: req._____.position).

If there are no optional queries, the server should respond with a JSON formatted string: {message: "all employees"}.

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

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

How is a normal probability plot used to detect outliers?

Answered: 1 week ago

Question

Write an equation for each parabola. (1, 2) (2, 1) 2 -2 -2- 2.

Answered: 1 week ago

Question

describe several successful positive work interventions.

Answered: 1 week ago