ENTD261 Week 4 Introduction: Node.js

Learning Goal: I’m working on a programming exercise and need an explanation and answer to help me learn.

Course name : ENTD261

Week 4: Node.js

Instructions

Create a simple Node.js server (Save as w4_fougnigue_soro.js) . Create a restful application similar to the one in lesson 4 (ReSTFul Web Services). Document the routing table, and the application you created.

Submit your week 4 work in w4_fougnigue_soro.txt (Please save the file as a text file and upload the text file here for final review.)

Note: node MUST be installed in the entd261 folder. Your code must be saved to the entd261 folder. node cannot be installed in any other folder. Be sure you have done this, or the code will not run in the command line.

Please refer to the attached sample solution file, w4_first_lastName.txt, for help. In place of first and lastName in the file name make sure your first and last names are present.

Requirements Points
Comment block. Instructions on how to run the code with examples 20
Code documentation and comments. 10
Assignment code including creating command line /URL parameter

(see routing table on how to document the URLs)

70
TOTAL POINTS 100

Reminder: This is what your ENTD261 folder should look like with node installed.

Attachments

w4_first_lastName.txt

(2.15 KB)

/*******************************************************************

***

***ENTD261

***

***Week 4

*** How to run: node w4_first_lastName.js

*** This Node.js app will display the inventory of a car shop.

***once the server is running, you will get

***Express server listening on port 44444

***from any browser enter http://localhost:44444/

*******************************************************************/

//setup

var express =require (“express”);

var http = require (“http”);

var app = express();

// run the server

app.listen(44444, function(){

console.log(“server is running on port 44444”);

})

// <<< here is the Model, the data storage

var vehicles = [

{id: 0, make: ‘toyota’, model: ‘corola’, year: 2019, color: ‘blue’},

{id: 1, make: ‘jeep’, model: ‘patriot’, year: 2016, color: ‘red’},

{id: 2, make: ‘honda’, model: ‘civic’, year: 2018, color: ‘white’},

{id: 3, make: ‘chevrolet’, model: ‘cruze’, year: 2019, color: ‘silver’}

];

// http://localhost:44444// general route

// here is the refer

app.get(“/”, function(req,res){

var message = “”

message += “<center><h1> Welcome to Pemon’s Car Shop </h1></center>”

message += “<center><h2>use the following </h2></center><br/>”

message += “<center> http://localhost:44444/about_us</center><br>”

message += “<center>http://localhost:44444/vehicles</center><br>”

message += “<center>http://localhost:44444/vehicles/3</center><br>”

res.send(message);

});

// <<< routes = controller

// http://localhost:44444/about_us// about_usroute

app.get(“/about_us”, function(req,res){

res.send(“We are here to serve you”);

});

// http://localhost:44444/vehicles// load and display all vehicles

app.get(‘/vehicles’, function(req, res){

res.send(JSON.stringify(vehicles));

});

// http://localhost:44444/vehicles/3// load and display vehicle id 3

app.get(‘/vehicles/:id’, function(req, res){

if(req.params.id > (vehicles.length -1) || req.params.id < 0){

res.statusCode = 404;

res.end(‘Vehicle Not Found’);

}

res.send(JSON.stringify(vehicles[req.params.id]))

});

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.