Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Node.js or Java Script Expert : please need help I need you to update server.js file to add support to JPEG ------server.js----- var fs =

Node.js or Java Script Expert : please need help

I need you to update server.js file to add support to JPEG

------server.js----- var fs = require('fs'); var path = require('path'); var http = require('http'); function send404(response) { response.writeHead(404, { 'Content-Type': 'text/html' }); response.write('Error 404: Resource not found.'); response.end(); } var mimeLookup = { '.js': 'application/javascript', '.html': 'text/html', }; var server = http.createServer(function (req, res) { if (req.method == 'GET') { // resolve file path to filesystem path  var fileurl; if (req.url == '/') fileurl = '/index.html'; else fileurl = req.url; var filepath = path.resolve('./' + fileurl); // lookup mime type  var fileExt = path.extname(filepath); var mimeType = mimeLookup[fileExt]; if (!mimeType) { send404(res); return; } // see if we have that file  fs.exists(filepath, function (exists) { // if not  if (!exists) { send404(res); return; }; // finally stream the file  res.writeHead(200, { 'content-type': mimeType }); fs.createReadStream(filepath).pipe(res); }); } else { send404(res); } }).listen(3000); console.log('server running on port 3000'); 

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

dy dx Find the derivative of the function y=(4x+3)5(2x+1)2.

Answered: 1 week ago

Question

Draw and explain the operation of LVDT for pressure measurement

Answered: 1 week ago

Question

Describe the appropriate use of supplementary parts of a letter.

Answered: 1 week ago