Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started