simple node js app || lyckas inte komma sidan. || LÖST

Permalänk
Medlem

simple node js app || lyckas inte komma sidan. || LÖST

Hej har gjort ett enkelt node js script med express, jag får inga errors av att köra scriptet men jag verka inte komma åt den heller.
Här nedan kommer information:

Dator: Ubuntu Gnome 16.04

node js version: 5.1.0

script:

//restapi.js //load the express var express = require('express'); var app = express(); // Get an instance of the express router var router = express.Router(); // Get body-parser. var bodyParser = require('body-parser'); // configure app to use body parser witch will // enable us to get data from .post (might be unessacary) app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); // Sets the port var port = process.env.PORT || 8080; //Create Courses variable var courses = []; //defualt data for the variable. courses[0] = '{"_id":1,"courseId":"DT162G","courseName":"Javascript-baserad webbutveckling","coursePeriod":1}'; courses[1] = '{"_id":2,"courseId":"IK060G","courseName":"Projektledning","coursePeriod":1}'; courses[2] = '{"_id":3,"courseId":"DT071G","courseName":"Programmering i C#.NET","coursePeriod":2}'; courses[3] = '{"_id":4,"courseId":"DT148G","courseName":"Webbutveckling för mobila enheter","coursePeriod":2}'; courses[4] = '{"_id":5,"courseId":"DT102G","courseName":"ASP.NET med C#","coursePeriod":3}'; courses[5] = '{"_id":6,"courseId":"IG021G","courseName":"Affärsplaner och kommersialisering","coursePeriod":3}'; courses[6] = '{"_id":7,"courseId":"DT069G","courseName":"Multimedia för webben","coursePeriod":4}'; courses[7] = '{"_id":8,"courseId":"DT080G","courseName":"Självständigt arbete","coursePeriod":4}'; /* * Get all courses */ router.get('/', function(req, res, next){ //Make the string typ in json format. var out = "["; for(row of courses){ out += row.replace("'", ""); out += ","; } out += "]"; out = out.replace(",]", "]"); console.log("Data being sent: all courses; "+out); //make a json parsing var jsonObj = JSON.parse(out); //fixing type res.ContentType('application/json'); //Sends the json object. res.send(jsonObj); }); /* * Get a specific course of id */ router.get('/:id', function(req, res, next){ var id = req.params.id; Found = "This courses doesn't exist"; for(row of courses){ //remove white space. tmp = row.replace(/\s+/g, ''); //Does not exisit anymore or ever. if(tmp.indexOf("_id\":\""+id+'\"','') > 0){ Found = row; } } console.log("Data being sent is: "+Found); res.ContentType('application/json'); res.send(Found); }); /* * Delete course according to id */ router.delete('/:id', function(req, res, next){ var id = req.params.id; var del = -1; var cnt = 0; for(row of courses){ // remove white space tmp=row.replace(/\s+/g, '') // find what should be deleted if(tmp.indexOf("_id\":\""+id+'\",')){ del = cnt; } cnt++; } if(del >= 0){ status = users.splice(del, 1); } console.log("id to be deleted: "+id); res.ContentType('application/json'); res.send(id); }); // Listen on port 8000, IP defaults to 127.0.0.1 app.listen(8080); // Write the server adress to the console console.log("Server running at http://127.0.0.1:8080/");

Project struktur:

ls -lR .: total 24 .: total 32 drwxrwxr-x 47 thisUser thisUser 12288 jun 10 11:51 node_modules -rwxrwxr-x 1 thisUser thisUser 2880 jun 10 12:02 restApi.js -rw-rw-r-- 1 thisUser thisUser 0 jun 10 12:09 tmp.txt ./node_modules: total 176 drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 accepts drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 array-flatten drwxrwxr-x 4 thisUser thisUser 4096 jun 10 11:51 body-parser drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 bytes drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 content-disposition drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 content-type drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 cookie drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 cookie-signature drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 debug drwxrwxr-x 3 thisUser thisUser 4096 jun 8 13:25 depd drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 destroy drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 ee-first drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 escape-html drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 etag drwxrwxr-x 3 thisUser thisUser 4096 jun 10 11:49 express drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 finalhandler drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 forwarded drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 fresh drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 http-errors drwxrwxr-x 4 thisUser thisUser 4096 jun 10 11:51 iconv-lite drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 inherits drwxrwxr-x 5 thisUser thisUser 4096 jun 8 13:25 ipaddr.js drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 media-typer drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 merge-descriptors drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 methods drwxrwxr-x 3 thisUser thisUser 4096 jun 8 13:25 mime drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 mime-db drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 mime-types drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 ms drwxrwxr-x 3 thisUser thisUser 4096 jun 8 13:25 negotiator drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 on-finished drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 parseurl drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 path-to-regexp drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 proxy-addr drwxrwxr-x 4 thisUser thisUser 4096 jun 8 13:25 qs drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 range-parser drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 raw-body drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 send drwxrwxr-x 3 thisUser thisUser 4096 jun 8 13:25 serve-static drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 statuses drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 type-is drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 unpipe drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 utils-merge drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 vary ./node_modules/accepts: total 64 -rw-rw-r-- 1 thisUser thisUser 3294 sep 7 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 5194 jun 8 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1167 jun 8 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2957 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3838 maj 7 2015 README.md ./node_modules/array-flatten: total 48 -rw-rw-r-- 1 thisUser thisUser 1195 jul 9 2015 array-flatten.js -rw-rw-r-- 1 thisUser thisUser 1103 mar 15 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2204 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1245 maj 9 2015 README.md ./node_modules/body-parser: total 88 -rw-rw-r-- 1 thisUser thisUser 10725 maj 6 07:31 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2649 maj 6 05:11 index.js drwxrwxr-x 3 thisUser thisUser 4096 jun 10 11:51 lib -rw-rw-r-- 1 thisUser thisUser 1172 maj 6 05:11 LICENSE drwxrwxr-x 4 thisUser thisUser 4096 jun 10 11:51 node_modules -rw-rw-r-- 1 thisUser thisUser 2935 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 14993 maj 6 06:22 README.md ./node_modules/body-parser/lib: total 16 -rw-rw-r-- 1 thisUser thisUser 3847 maj 6 05:11 read.js drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 types ./node_modules/body-parser/lib/types: total 52 -rw-rw-r-- 1 thisUser thisUser 3627 maj 6 05:11 json.js -rw-rw-r-- 1 thisUser thisUser 1847 maj 6 05:11 raw.js -rw-rw-r-- 1 thisUser thisUser 2238 maj 6 05:11 text.js -rw-rw-r-- 1 thisUser thisUser 5611 maj 6 05:11 urlencoded.js ./node_modules/body-parser/node_modules: total 8 drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 http-errors drwxrwxr-x 5 thisUser thisUser 4096 jun 10 11:51 qs ./node_modules/body-parser/node_modules/http-errors: total 60 -rw-rw-r-- 1 thisUser thisUser 1675 jan 29 06:22 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 3094 jan 29 05:59 index.js -rw-rw-r-- 1 thisUser thisUser 1099 jan 22 22:18 LICENSE -rw-rw-r-- 1 thisUser thisUser 2717 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 2160 jan 29 06:02 README.md ./node_modules/body-parser/node_modules/qs: total 108 -rw-rw-r-- 1 thisUser thisUser 427 feb 4 06:52 bower.json -rw-rw-r-- 1 thisUser thisUser 7519 feb 4 06:52 CHANGELOG.md -rw-rw-r-- 1 thisUser thisUser 353 feb 4 06:52 component.json -rw-rw-r-- 1 thisUser thisUser 105 dec 23 08:40 CONTRIBUTING.md drwxrwxr-x 2 thisUser thisUser 4096 feb 4 06:59 dist drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 lib -rw-rw-r-- 1 thisUser thisUser 1654 dec 23 08:40 LICENSE -rw-rw-r-- 1 thisUser thisUser 2723 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 9884 jan 17 23:24 README.md drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 test ./node_modules/body-parser/node_modules/qs/dist: total 24 -rw-rw-r-- 1 thisUser thisUser 14547 feb 4 06:59 qs.js ./node_modules/body-parser/node_modules/qs/lib: total 56 -rwxrwxr-x 1 thisUser thisUser 153 jan 17 18:34 index.js -rwxrwxr-x 1 thisUser thisUser 5248 feb 3 06:08 parse.js -rwxrwxr-x 1 thisUser thisUser 3979 feb 4 06:50 stringify.js -rwxrwxr-x 1 thisUser thisUser 4121 feb 3 06:08 utils.js ./node_modules/body-parser/node_modules/qs/test: total 68 -rw-rw-r-- 1 thisUser thisUser 66 dec 23 10:11 index.js -rwxrwxr-x 1 thisUser thisUser 15918 feb 3 06:08 parse.js -rwxrwxr-x 1 thisUser thisUser 10480 feb 4 06:50 stringify.js -rwxrwxr-x 1 thisUser thisUser 242 feb 3 06:08 utils.js ./node_modules/bytes: total 60 -rw-rw-r-- 1 thisUser thisUser 1225 feb 16 04:59 History.md -rw-rw-r-- 1 thisUser thisUser 3213 feb 16 04:01 index.js -rw-rw-r-- 1 thisUser thisUser 1153 feb 16 01:53 LICENSE -rw-rw-r-- 1 thisUser thisUser 2586 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 3130 feb 16 01:53 Readme.md ./node_modules/content-disposition: total 72 -rw-rw-r-- 1 thisUser thisUser 768 jan 17 21:59 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 10208 jan 17 21:24 index.js -rw-rw-r-- 1 thisUser thisUser 1089 mar 25 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2475 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 5145 mar 25 2015 README.md ./node_modules/content-type: total 64 -rw-rw-r-- 1 thisUser thisUser 265 maj 10 05:57 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 4692 maj 10 05:06 index.js -rw-rw-r-- 1 thisUser thisUser 1089 maj 10 05:06 LICENSE -rw-rw-r-- 1 thisUser thisUser 2561 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2796 maj 10 05:06 README.md ./node_modules/cookie: total 60 -rw-rw-r-- 1 thisUser thisUser 1515 sep 17 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 3372 sep 17 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1199 sep 17 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2481 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1894 sep 17 2015 README.md ./node_modules/cookie-signature: total 48 -rw-rw-r-- 1 thisUser thisUser 695 feb 3 2015 History.md -rw-rw-r-- 1 thisUser thisUser 1230 feb 3 2015 index.js -rw-rw-r-- 1 thisUser thisUser 2112 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1490 jun 19 2014 Readme.md ./node_modules/debug: total 120 -rw-rw-r-- 1 thisUser thisUser 480 maj 10 2015 bower.json -rw-rw-r-- 1 thisUser thisUser 3763 maj 9 2015 browser.js -rw-rw-r-- 1 thisUser thisUser 309 maj 10 2015 component.json -rw-rw-r-- 1 thisUser thisUser 4096 aug 20 2014 debug.js -rw-rw-r-- 1 thisUser thisUser 5611 maj 9 2015 History.md -rw-rw-r-- 1 thisUser thisUser 715 maj 9 2015 Makefile -rw-rw-r-- 1 thisUser thisUser 4758 mar 13 2015 node.js -rw-rw-r-- 1 thisUser thisUser 2290 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 6310 maj 9 2015 Readme.md ./node_modules/depd: total 80 -rw-rw-r-- 1 thisUser thisUser 1839 sep 14 2015 History.md -rw-rw-r-- 1 thisUser thisUser 10527 sep 7 2015 index.js drwxrwxr-x 4 thisUser thisUser 4096 jun 8 13:25 lib -rw-rw-r-- 1 thisUser thisUser 1094 sep 7 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2386 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 10142 sep 7 2015 Readme.md ./node_modules/depd/lib: total 8 drwxrwxr-x 2 thisUser thisUser 4096 sep 7 2015 browser drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 compat ./node_modules/depd/lib/browser: total 12 -rw-rw-r-- 1 thisUser thisUser 1518 sep 7 2015 index.js ./node_modules/depd/lib/compat: total 48 -rw-rw-r-- 1 thisUser thisUser 506 sep 7 2015 buffer-concat.js -rw-rw-r-- 1 thisUser thisUser 2226 sep 7 2015 callsite-tostring.js -rw-rw-r-- 1 thisUser thisUser 337 sep 7 2015 event-listener-count.js -rw-rw-r-- 1 thisUser thisUser 1574 sep 7 2015 index.js ./node_modules/destroy: total 48 -rw-rw-r-- 1 thisUser thisUser 1043 jan 13 17:13 index.js -rw-rw-r-- 1 thisUser thisUser 1099 aug 14 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2412 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2185 jan 13 17:29 README.md ./node_modules/ee-first: total 48 -rw-rw-r-- 1 thisUser thisUser 1684 maj 25 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1099 aug 15 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2387 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2617 maj 25 2015 README.md ./node_modules/escape-html: total 48 -rw-rw-r-- 1 thisUser thisUser 1362 sep 1 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1157 sep 1 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2090 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 707 sep 1 2015 Readme.md ./node_modules/etag: total 64 -rw-rw-r-- 1 thisUser thisUser 1458 jun 9 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2517 jun 9 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1094 maj 11 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2476 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 4152 jun 5 2015 README.md ./node_modules/express: total 164 -rw-rw-r-- 1 thisUser thisUser 95032 jan 22 03:10 History.md -rw-rw-r-- 1 thisUser thisUser 224 nov 14 2015 index.js drwxrwxr-x 4 thisUser thisUser 4096 jun 8 13:25 lib -rw-rw-r-- 1 thisUser thisUser 1249 nov 14 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 4197 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 4136 jan 22 03:04 Readme.md ./node_modules/express/lib: total 128 -rw-rw-r-- 1 thisUser thisUser 14202 dec 1 2015 application.js -rw-rw-r-- 1 thisUser thisUser 1954 nov 14 2015 express.js drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 middleware -rw-rw-r-- 1 thisUser thisUser 11342 nov 14 2015 request.js -rw-rw-r-- 1 thisUser thisUser 24757 nov 14 2015 response.js drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 router -rw-rw-r-- 1 thisUser thisUser 5797 nov 14 2015 utils.js -rw-rw-r-- 1 thisUser thisUser 3142 nov 14 2015 view.js ./node_modules/express/lib/middleware: total 24 -rw-rw-r-- 1 thisUser thisUser 752 nov 14 2015 init.js -rw-rw-r-- 1 thisUser thisUser 923 nov 14 2015 query.js ./node_modules/express/lib/router: total 48 -rw-rw-r-- 1 thisUser thisUser 14488 nov 14 2015 index.js -rw-rw-r-- 1 thisUser thisUser 3124 nov 14 2015 layer.js -rw-rw-r-- 1 thisUser thisUser 4029 nov 14 2015 route.js ./node_modules/finalhandler: total 60 -rw-rw-r-- 1 thisUser thisUser 2007 dec 2 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 3000 jun 14 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1119 jun 14 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2735 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3305 mar 16 2015 README.md ./node_modules/forwarded: total 60 -rw-rw-r-- 1 thisUser thisUser 59 sep 21 2014 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 641 sep 21 2014 index.js -rw-rw-r-- 1 thisUser thisUser 1089 sep 19 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2326 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1432 sep 21 2014 README.md ./node_modules/fresh: total 60 -rw-rw-r-- 1 thisUser thisUser 600 maj 12 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 1300 maj 12 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1098 maj 12 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2763 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1393 maj 12 2015 README.md ./node_modules/http-errors: total 60 -rw-rw-r-- 1 thisUser thisUser 1431 feb 3 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2936 feb 3 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1099 sep 11 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2657 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1949 sep 11 2014 README.md ./node_modules/iconv-lite: total 60 -rw-rw-r-- 1 thisUser thisUser 2288 okt 2 2015 Changelog.md drwxrwxr-x 3 thisUser thisUser 4096 jun 10 11:51 encodings drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 lib -rw-rw-r-- 1 thisUser thisUser 1064 nov 9 2011 LICENSE -rw-rw-r-- 1 thisUser thisUser 3373 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 6399 sep 26 2015 README.md ./node_modules/iconv-lite/encodings: total 184 -rw-rw-r-- 1 thisUser thisUser 21360 maj 24 2015 dbcs-codec.js -rw-rw-r-- 1 thisUser thisUser 8112 maj 24 2015 dbcs-data.js -rw-rw-r-- 1 thisUser thisUser 709 maj 24 2015 index.js -rw-rw-r-- 1 thisUser thisUser 6058 sep 26 2015 internal.js -rw-rw-r-- 1 thisUser thisUser 2158 maj 24 2015 sbcs-codec.js -rw-rw-r-- 1 thisUser thisUser 32034 maj 24 2015 sbcs-data-generated.js -rw-rw-r-- 1 thisUser thisUser 4320 maj 24 2015 sbcs-data.js drwxrwxr-x 2 thisUser thisUser 4096 jun 10 11:51 tables -rw-rw-r-- 1 thisUser thisUser 4882 maj 27 2015 utf16.js -rw-rw-r-- 1 thisUser thisUser 9156 maj 24 2015 utf7.js ./node_modules/iconv-lite/encodings/tables: total 292 -rw-rw-r-- 1 thisUser thisUser 17717 maj 28 2014 big5-added.json -rw-rw-r-- 1 thisUser thisUser 47320 maj 28 2014 cp936.json -rw-rw-r-- 1 thisUser thisUser 38122 maj 28 2014 cp949.json -rw-rw-r-- 1 thisUser thisUser 42356 maj 28 2014 cp950.json -rw-rw-r-- 1 thisUser thisUser 41064 maj 28 2014 eucjp.json -rw-rw-r-- 1 thisUser thisUser 2216 maj 28 2014 gb18030-ranges.json -rw-rw-r-- 1 thisUser thisUser 1227 maj 28 2014 gbk-added.json -rw-rw-r-- 1 thisUser thisUser 23782 maj 28 2014 shiftjis.json ./node_modules/iconv-lite/lib: total 60 -rw-rw-r-- 1 thisUser thisUser 1108 maj 24 2015 bom-handling.js -rw-rw-r-- 1 thisUser thisUser 8513 okt 2 2015 extend-node.js -rw-rw-r-- 1 thisUser thisUser 4521 maj 24 2015 index.js -rw-rw-r-- 1 thisUser thisUser 3347 maj 24 2015 streams.js ./node_modules/inherits: total 72 -rw-rw-r-- 1 thisUser thisUser 672 maj 16 2013 inherits_browser.js -rw-rw-r-- 1 thisUser thisUser 42 maj 16 2013 inherits.js -rw-rw-r-- 1 thisUser thisUser 749 aug 20 2013 LICENSE -rw-rw-r-- 1 thisUser thisUser 1852 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1625 maj 16 2013 README.md -rw-rw-r-- 1 thisUser thisUser 510 maj 16 2013 test.js ./node_modules/ipaddr.js: total 92 -rw-rw-r-- 1 thisUser thisUser 543 dec 9 2015 bower.json -rw-rw-r-- 1 thisUser thisUser 624 dec 9 2015 Cakefile -rw-rw-r-- 1 thisUser thisUser 6771 dec 9 2015 ipaddr.min.js drwxrwxr-x 2 thisUser thisUser 4096 dec 9 2015 lib -rw-rw-r-- 1 thisUser thisUser 1082 dec 9 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2058 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 5948 dec 9 2015 README.md drwxrwxr-x 2 thisUser thisUser 4096 dec 9 2015 src drwxrwxr-x 2 thisUser thisUser 4096 dec 9 2015 test ./node_modules/ipaddr.js/lib: total 24 -rw-rw-r-- 1 thisUser thisUser 13539 dec 9 2015 ipaddr.js ./node_modules/ipaddr.js/src: total 24 -rw-rw-r-- 1 thisUser thisUser 12625 dec 9 2015 ipaddr.coffee ./node_modules/ipaddr.js/test: total 24 -rw-rw-r-- 1 thisUser thisUser 12880 dec 9 2015 ipaddr.test.coffee ./node_modules/media-typer: total 64 -rw-rw-r-- 1 thisUser thisUser 461 sep 8 2014 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 6375 sep 8 2014 index.js -rw-rw-r-- 1 thisUser thisUser 1089 sep 8 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2260 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2371 sep 8 2014 README.md ./node_modules/merge-descriptors: total 60 -rw-rw-r-- 1 thisUser thisUser 363 jan 18 00:41 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 1215 jan 18 00:39 index.js -rw-rw-r-- 1 thisUser thisUser 1167 jan 18 00:39 LICENSE -rw-rw-r-- 1 thisUser thisUser 3983 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1213 maj 22 2015 README.md ./node_modules/methods: total 60 -rw-rw-r-- 1 thisUser thisUser 427 jan 18 03:40 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 1040 jan 18 02:02 index.js -rw-rw-r-- 1 thisUser thisUser 1180 jan 18 02:02 LICENSE -rw-rw-r-- 1 thisUser thisUser 2782 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1694 jan 18 02:17 README.md ./node_modules/mime: total 104 drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 build -rwxrwxr-x 1 thisUser thisUser 149 feb 5 2015 cli.js -rw-rw-r-- 1 thisUser thisUser 1075 maj 10 2011 LICENSE -rw-rw-r-- 1 thisUser thisUser 2671 feb 5 2015 mime.js -rw-rw-r-- 1 thisUser thisUser 2280 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2119 feb 5 2015 README.md -rw-rw-r-- 1 thisUser thisUser 29681 feb 7 2015 types.json ./node_modules/mime/build: total 24 -rw-rw-r-- 1 thisUser thisUser 231 feb 5 2015 build.js -rw-rw-r-- 1 thisUser thisUser 2184 feb 5 2015 test.js ./node_modules/mime-db: total 220 -rw-rw-r-- 1 thisUser thisUser 143991 maj 2 06:16 db.json -rw-rw-r-- 1 thisUser thisUser 9141 maj 2 06:19 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 136 sep 25 2014 index.js -rw-rw-r-- 1 thisUser thisUser 1099 sep 25 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 3229 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2991 dec 10 2015 README.md ./node_modules/mime-types: total 60 -rw-rw-r-- 1 thisUser thisUser 3577 maj 2 06:55 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 3645 feb 15 21:45 index.js -rw-rw-r-- 1 thisUser thisUser 1167 feb 15 21:45 LICENSE -rw-rw-r-- 1 thisUser thisUser 2943 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2924 feb 15 22:39 README.md ./node_modules/ms: total 60 -rw-rw-r-- 1 thisUser thisUser 1307 apr 21 2015 History.md -rw-rw-r-- 1 thisUser thisUser 2332 apr 21 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1097 apr 21 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 1712 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 933 apr 21 2015 README.md ./node_modules/negotiator: total 68 -rw-rw-r-- 1 thisUser thisUser 1529 maj 11 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2134 maj 5 2015 index.js drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 lib -rw-rw-r-- 1 thisUser thisUser 1177 maj 11 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2762 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 4805 feb 15 2015 README.md ./node_modules/negotiator/lib: total 48 -rw-rw-r-- 1 thisUser thisUser 2259 feb 15 2015 charset.js -rw-rw-r-- 1 thisUser thisUser 2673 feb 15 2015 encoding.js -rw-rw-r-- 1 thisUser thisUser 2575 feb 15 2015 language.js -rw-rw-r-- 1 thisUser thisUser 3766 maj 11 2015 mediaType.js ./node_modules/on-finished: total 64 -rw-rw-r-- 1 thisUser thisUser 1694 maj 27 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 3686 maj 26 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1167 aug 16 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2583 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 4886 maj 26 2015 README.md ./node_modules/parseurl: total 60 -rw-rw-r-- 1 thisUser thisUser 832 jan 17 20:46 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2425 jan 17 20:41 index.js -rw-rw-r-- 1 thisUser thisUser 1168 aug 10 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2915 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3463 jan 17 20:46 README.md ./node_modules/path-to-regexp: total 64 -rw-rw-r-- 1 thisUser thisUser 694 jul 28 2015 History.md -rw-rw-r-- 1 thisUser thisUser 3328 jul 28 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1103 jul 28 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 4607 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1102 jul 28 2015 Readme.md ./node_modules/proxy-addr: total 64 -rw-rw-r-- 1 thisUser thisUser 1535 dec 10 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 6171 dec 10 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1089 sep 18 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2885 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3990 dec 10 2015 README.md ./node_modules/qs: total 88 -rw-rw-r-- 1 thisUser thisUser 449 jul 1 2015 bower.json -rw-rw-r-- 1 thisUser thisUser 5844 jul 1 2015 CHANGELOG.md -rw-rw-r-- 1 thisUser thisUser 105 jul 1 2015 CONTRIBUTING.md drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 lib -rw-rw-r-- 1 thisUser thisUser 1654 jul 1 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 1988 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 8127 jul 2 2015 README.md drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 test ./node_modules/qs/lib: total 56 -rw-rw-r-- 1 thisUser thisUser 200 jul 1 2015 index.js -rw-rw-r-- 1 thisUser thisUser 5288 jul 2 2015 parse.js -rw-rw-r-- 1 thisUser thisUser 3072 jul 1 2015 stringify.js -rw-rw-r-- 1 thisUser thisUser 4319 jul 2 2015 utils.js ./node_modules/qs/test: total 60 -rw-rw-r-- 1 thisUser thisUser 16977 jul 2 2015 parse.js -rw-rw-r-- 1 thisUser thisUser 8549 jul 2 2015 stringify.js -rw-rw-r-- 1 thisUser thisUser 507 jul 1 2015 utils.js ./node_modules/range-parser: total 60 -rw-rw-r-- 1 thisUser thisUser 574 okt 26 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 1078 okt 26 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1100 sep 9 2014 LICENSE -rw-rw-r-- 1 thisUser thisUser 2564 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1549 okt 26 2015 README.md ./node_modules/raw-body: total 64 -rw-rw-r-- 1 thisUser thisUser 3803 mar 8 04:03 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 6762 jan 16 06:10 index.js -rw-rw-r-- 1 thisUser thisUser 1203 maj 7 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2933 jun 10 11:51 package.json -rw-rw-r-- 1 thisUser thisUser 3848 maj 8 2015 README.md ./node_modules/send: total 84 -rw-rw-r-- 1 thisUser thisUser 7020 jan 16 08:38 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 17429 jun 17 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1128 feb 16 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2761 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 5697 feb 16 2015 README.md ./node_modules/serve-static: total 72 -rw-rw-r-- 1 thisUser thisUser 6488 maj 31 05:18 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 4011 maj 31 00:19 index.js -rw-rw-r-- 1 thisUser thisUser 1189 maj 30 23:57 LICENSE drwxrwxr-x 3 thisUser thisUser 4096 jun 8 13:25 node_modules -rw-rw-r-- 1 thisUser thisUser 3019 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 6825 maj 30 23:57 README.md ./node_modules/serve-static/node_modules: total 4 drwxrwxr-x 2 thisUser thisUser 4096 jun 8 13:25 send ./node_modules/serve-static/node_modules/send: total 84 -rw-rw-r-- 1 thisUser thisUser 7136 mar 6 05:21 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 17501 mar 6 03:42 index.js -rw-rw-r-- 1 thisUser thisUser 1128 feb 16 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2862 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 6733 mar 6 04:35 README.md ./node_modules/statuses: total 60 -rw-rw-r-- 1 thisUser thisUser 1764 feb 2 2015 codes.json -rw-rw-r-- 1 thisUser thisUser 1135 feb 2 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1099 feb 2 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2761 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3096 feb 2 2015 README.md ./node_modules/type-is: total 64 -rw-rw-r-- 1 thisUser thisUser 3731 maj 19 03:36 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 5525 maj 19 03:35 index.js -rw-rw-r-- 1 thisUser thisUser 1172 jul 19 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2898 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 3718 maj 10 04:25 README.md ./node_modules/unpipe: total 60 -rw-rw-r-- 1 thisUser thisUser 59 jun 14 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 1118 jun 14 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1114 jun 14 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2253 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 1250 jun 14 2015 README.md ./node_modules/utils-merge: total 48 -rw-rw-r-- 1 thisUser thisUser 381 jul 11 2013 index.js -rw-rw-r-- 1 thisUser thisUser 1075 jul 11 2013 LICENSE -rw-rw-r-- 1 thisUser thisUser 2079 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 634 jul 11 2013 README.md ./node_modules/vary: total 60 -rw-rw-r-- 1 thisUser thisUser 470 jul 9 2015 HISTORY.md -rw-rw-r-- 1 thisUser thisUser 2172 jul 6 2015 index.js -rw-rw-r-- 1 thisUser thisUser 1094 jul 6 2015 LICENSE -rw-rw-r-- 1 thisUser thisUser 2406 jun 8 13:25 package.json -rw-rw-r-- 1 thisUser thisUser 2361 feb 15 2015 README.md

RESTClient test: get

  • Är det koden eller något annat?

  • I fall det är koden ser något ett upenbart fel?

Tack för hjälpen!

Visa signatur

Смерть -это решение всех проблем. Нет человека - нет проблемы
Comp1: Ubuntu 16.04 Comp2: Arch Linux
Comp3: Ubuntu Server 16.04 Comp4: Centos 6.5
Comp5: Linux mint 16 Comp6: Raspberry pi (olika OS hela tiden)
Phone: Motorola Google Nexus 6

Permalänk
Medlem

Ska även tillägga att utskrifterna i vardera funktion inte skrivs ut i terminalen eller konsolen.

Visa signatur

Смерть -это решение всех проблем. Нет человека - нет проблемы
Comp1: Ubuntu 16.04 Comp2: Arch Linux
Comp3: Ubuntu Server 16.04 Comp4: Centos 6.5
Comp5: Linux mint 16 Comp6: Raspberry pi (olika OS hela tiden)
Phone: Motorola Google Nexus 6

Permalänk
Medlem

Allt är löst nu enligt RESTClient iaf.

Bara dålig kod nu är den omskriven till denna:

//restapi.js //load the express var express = require('express'); var app = express(); // Get body-parser. var bodyParser = require('body-parser'); // configure app to use body parser witch will // enable us to get data from .post (might be unessacary) app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); // Sets the port var port = process.env.PORT || 8080; //Create Courses variable var courses = [ {_id : 1, courseId : "DT162G", courseName : "Javascript-baserad webbutveckling", coursePeriod : 1}, {_id : 2, courseId : "IK060G", courseName : "Projektledning", coursePeriod : 1}, {_id : 3, courseId : "DT071G", courseName : "Programmering i C#.NET", coursePeriod : 2}, {_id : 4, courseId : "DT148G", courseName : "Webbutveckling för mobila enheter", coursePeriod : 2}, {_id : 5, courseId : "DT102G", courseName : "ASP.NET med C#", coursePeriod : 3}, {_id : 6, courseId : "IG021G", courseName : "Affärsplaner och kommersialisering", coursePeriod : 3}, {_id : 7, courseId : "DT069G", courseName : "Multimedia för webben", coursePeriod : 4}, {_id : 8, courseId : "DT080G", courseName : "Självständigt arbete", coursePeriod : 4} ]; /* * Get all courses */ app.get('/', function(req, res, next){ console.log("All"); res.json(courses); }); /* * Get a specific course of id */ app.get('/:id', function(req, res, next){ var Found = [{text : "This courses doesn't exist"}]; var id = req.params.id; for(row of courses){ if(row._id == id){ Found = row; } } console.log("Sent data: "+Found); // res.ContentType('application/json'); res.json(Found); }); /* * Delete course according to id */ app.delete('/:id', function(req, res, next){ var id = req.params.id; var del = -1; var cnt = 0; for(row of courses){ // find what should be deleted if(row._id == id){ del = cnt; } cnt++; } var found = [{text: "Not found"}]; if(del >= 0){ courses.splice(del, 1); res.statusCode = 200; console.log("id that gets deleted: "+id); found = [{text: "Done"}]; } else{ res.statusCode = 404; console.log("Id not found (delete)"); } res.json(found); }); // Lisen to port, app.listen(port); // Write the server adress to the console console.log("Server running at http://127.0.0.1:8080/");

Visa signatur

Смерть -это решение всех проблем. Нет человека - нет проблемы
Comp1: Ubuntu 16.04 Comp2: Arch Linux
Comp3: Ubuntu Server 16.04 Comp4: Centos 6.5
Comp5: Linux mint 16 Comp6: Raspberry pi (olika OS hela tiden)
Phone: Motorola Google Nexus 6