Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a very basic web server in JavaScript that will run via nodejs. The projec

ID: 3810385 • Letter: W

Question

Write a very basic web server in JavaScript that will run via nodejs. The project accepts HTTP requests via URLS in the format

/[a-Za-Z0-9_]*.php

The project shall include the following line:

var paul = require('/homes/paul/HTML/CS316/p3_req.js');

- For URLs ending in .php, your program shall do the following:

1) retrieve the value returned from paul.whatphp().      

2) retrieve the value returned from paul.ppath().  

3) call exec() with the command retrieved from #1 and     the "MYHTML/" directory and the file the user requested via the URL (minus the /). You will also need to set the env option to set the PATH to use only the value you retrieved from #2.      

4) if the exec() call fails, you shall return an error message to the user's client via response.

5) after execution, you should return the output of the exec()     call to the user's client in the response. You can set the content-type to "text/html".

- The modules you will want to use are: http, fs, and child_process.

- Additionally, as stated above, you MUST include (via 'require')      the p3_req.js file in my account!

Explanation / Answer


var fs = require("fs");
var paul = require('/homes/paul/HTML/CS316/p3_req.js');
var options = {
env : "",
           path : paul.ppath(),
           content-type :"text/html"
};
var exec = require('child_process').exec;
exec(paul.whatphp(),options, (error, output, secondaryError) => {
if (error) {
console.error("error",error);
return;
}
console.log("output",output);
});

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote