I love you! This series is still helpful in 2020! I'm starting with React and Express and this helped me a lot with building an app with APIs and json files. I'm going to learn databases next. :D Thank you!
I've always imagined that you made these videos at the university, but after 12:48 when the puppy began barking, I got the impression that you are doing your magic in your home. Not that it matters to me at all.
I know this is a old video, but someone watching this right now. Shiffman made one huge error with his test for if the word can be found inside of words in the searchWord -function. if (words[word]) will act as a false also if the score happens to be 0. To fix this use Objects built in function hasOwnProperty ex. if (words.hasOwnProperty(word)) which instead tells javascript to look inside words for a property (key) named whatever is given in word
are you going to do another coding challenge? i am a 22 year old university student and i started coding because of your coding challenge video, i really appreciate what you do
it gives me this error . if i run the code. internal/modules/cjs/loader.js:968 throw err; ^ Error: Cannot find module 'E: ode\exp.js' [90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)[39m [90m at Function.Module._load (internal/modules/cjs/loader.js:841:27)[39m [90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m [90m at internal/main/run_main_module.js:17:47[39m { code: [32m'MODULE_NOT_FOUND'[39m, requireStack: [] }
I have questions Why do you use 'GET' On adding data to '/add' route? Is it suppose to be done by 'POST'? Or it is ok to do all the CRUD operation in 'GET'? I am so confusing And also how to define the method of the request at the front-end?
I believe the GET is done for only demonstrative purposes. It’s better to use POST for this example, but since you can’t test that with just a URL it’s a little beyond this video. If we were using Postman or another HTTP application, we could test the route handler for POST, instead of using GET in a non ideal way. For your second question, look into HTML forms. The only Http verbs available to forms are GET and POST, but these can serve most of your needs for something simple.
I got a CannotGet error and it took me almost an hour finding out, what was wrong. I've written: app.get('add/:word/:score', addWord); instead of app.get('/add/:word/:score', addWord);
classic programming problem, you understand the general idea and the more complex process but you missed a forward slash. Spend 5 hours seeing if all the files are connected, check if node is properly downloaded, nothing works. You come back the next day and realise you added a forward slash by accident.
Hi- there’s no need to check for if the parameter :word is included, since that route will only be handled if there is a value for that parameter in the URL.
words[word] = score; I understand most parts of the code, but I can not understand the code above. Can somebody tell me why the line above works? Thank you so much in advance.
this code is adding "on the fly" new pair of key-value. word is key, score is value. Javascript allows that. And word is variable (string), that was assigned some lines above from data.word.
pls i wrote this code and it showing cannot get for this URL (localhost:add/book) and i was expecting (score is required) var words = { "Rainbow": 5, "Unicorn": 3, "Doom": -3, "Goom": -2 }; var express = require('express'); var app =express(); app.get('/add/:word/:score', addWord) ; function addWord(request, response){ var data = request.params; var word = data.word; var score = Number(data.score); var reply; if( !score){ reply = { msg: "Score is required" } } else { words[word] = score; reply = { msg: "thank you for your word" } response.send(reply); } } app.get('/all', sendAll ) function sendAll(request, response){ response.send(words) } app.listen(1000);
Yes, and thank you for explaining routing in node. I guess I can't think of an instance where it would be better to actually change the variable in the .js file that is being executed at the moment by, perhaps loading the file into a string and splitting it where the variable ends, and then adding the data, joining the string and saving it. Just more of a thought experiment/hack than anything else.