Node.js Crash Course Tutorial #10 - Get, Post & Delete Requests

Поділитися
Вставка
  • Опубліковано 2 жов 2024

КОМЕНТАРІ • 369

  • @mouhamethfadalmarabyaidara4935
    @mouhamethfadalmarabyaidara4935 4 роки тому +183

    I swear this tutorial is far better than the premium (paid) ones that we see on Udemy or other e-learning platform.
    You are so much knowledgeable about the topics that i'm just stunned .
    Big respect for you and thanks for changing the lives of thousands of software engineers by making them understand actually the core concepts.

  • @NetNinja
    @NetNinja  4 роки тому +232

    Make sure you place the blogs/create GET route ABOVE the /blogs/:id GET route in the code. Otherwise express will fire the /blogs/:id handler for requests to /blogs/create.

    • @TechnoDB
      @TechnoDB 4 роки тому +10

      Oh... I was stuck at this and it took my time.
      Also, you've mentioned this stuff in your next video. :v

    • @ashishchourasia2830
      @ashishchourasia2830 4 роки тому

      I am getting 'TypeError: Cannot read property 'id' of undefined' at the params line.
      VS code wasn't showing the intellisense for it. Please help

    • @andressiri
      @andressiri 4 роки тому +7

      @@ashishchourasia2830 what fix this for me was going back to index.ejs and on the tag make sure the href link has the same spacing with the ejs tags like in the video.

    • @LavishArora11
      @LavishArora11 4 роки тому

      Thanks man, that's where it got stuck.

    • @krasimirkraev8716
      @krasimirkraev8716 4 роки тому

      I dont get this. Can you explain a bit more please.

  • @Shakeel714
    @Shakeel714 3 роки тому +13

    This series on NodeJS is better than any other series/course on YoutTube or Udemy

  • @layeekromah4799
    @layeekromah4799 4 роки тому +98

    This is by far the best crash course ever, feels almost like the best premium course on nodejs. The style of teaching rocks!

  • @SALMANKHAN-zz4gi
    @SALMANKHAN-zz4gi 4 роки тому +46

    i feel butterflies in my stomach . the excitement of understanding the concept and yearning to apply it to a project is too much . Thanks ninja

  • @pwrs7
    @pwrs7 9 місяців тому +1

    Loved the content. Gave me great learning over the weekend. I loved how he builds the pieces early on and how they all come together at the end to form an application. Not only gives you the details on how it can be done, but also why things are done the way they are done. Loved it. Huge thanks.

    • @NetNinja
      @NetNinja  9 місяців тому

      That's awesome to hear :) thanks so much for watching

  • @stana_andrei4752
    @stana_andrei4752 4 роки тому +62

    Can you make a tutorial on how to connect a react component with node backend?

    • @dnynu
      @dnynu 4 роки тому +5

      Yaa I also want 👍

    • @F4ILCON
      @F4ILCON 4 роки тому +11

      Keep in mind that this is server side rending using EJS, nodejs render html to the browser, now React, Angular, Vue they have different approach, so you need to make http request from react to reach the routes in nodeJS, you also probably need set CORS on nodejs. Create nodejs Server with route and react app to call these route.

    • @AccessCode101
      @AccessCode101 4 роки тому +10

      @@F4ILCON Sounds like you know what you're talking about. Can you make a quick video, please!

    • @alexanderbugay6752
      @alexanderbugay6752 4 роки тому +16

      Maybe you might want to check out some videos on the topic from another coding guru:
      Part 1: ua-cam.com/video/XuFDcZABiDQ/v-deo.html
      Part 2: ua-cam.com/video/KyWaXA_NvT0/v-deo.html
      He also has MERN stack mini series which I found really useful. Though NetNinja's accent is 1000 times better so I'm also waiting for this tutorial

    • @jmbeatsbbx
      @jmbeatsbbx 4 роки тому

      Which Node features would you use if you had React already tho?

  • @LoveisHell85
    @LoveisHell85 3 роки тому +14

    Please make a react/node/SQL tutorial. I would love to see a complete fullstack project (ecommerce site perhaps). I would be more than happy to pay for a premium course.
    Thank you for the great content!

  • @ArmanAghajanyan-eh1tn
    @ArmanAghajanyan-eh1tn 5 місяців тому

    Best ever tutorial. thank you Shaun Pelling. Huge contribution to learners!!!

    • @NetNinja
      @NetNinja  5 місяців тому

      Glad it was helpful! :)

  • @stanisawjarocki1747
    @stanisawjarocki1747 2 роки тому +4

    // If you get error around 19:11, which looks like this:
    CastError: Cast to ObjectId failed for value "style.css" (type string) at path "_id" for model "Blog"
    // Then simply remove from details.ejs
    // I don't understand why, but with only this:
    const id = req.params.id;
    console.log(id);
    // id looks fine, but when you add this below:
    Blog.findById(id)
    .then((result) => {
    res.render("details", { title: "Blog Details", blog: result });
    })
    .catch((err) => {
    console.log(err);
    });
    // another id shows up in console:
    6308f2bbcb373829482ab874
    style.css
    // Is anyone able to explain this?

    • @adetunjiojekunle1502
      @adetunjiojekunle1502 Рік тому

      I have this same error as well

    • @adetunjiojekunle1502
      @adetunjiojekunle1502 Рік тому +5

      [SOLVED] add '/' before styles.css in head.ejs, so you have it as '/styles.css'

    • @dolusdirectu
      @dolusdirectu Рік тому +1

      @@adetunjiojekunle1502 Thx m8

    • @prismanic24
      @prismanic24 Рік тому

      Took me an entire day to figure out why I was getting this error, thanks!

  • @iamabhirupdatta
    @iamabhirupdatta 3 роки тому +6

    If anyone getting undefined value in req.body for the post request , add the following before any route:
    app.use(express.urlencoded({extended: true}));
    app.use(express.json());

  • @pipertime1
    @pipertime1 3 роки тому +11

    This is well taught! It's very complex! Why? It seems PHP can do all this much easier and not as complex. It's feels like trying to reinvent the wheel. It may just be me.........
    I have learned a lot from Shaun on Udemy!

    • @manasnagelia
      @manasnagelia 3 роки тому +2

      Totally agree. PHP is easier. But, Node.js is faster than PHP, and PHP is getting outdated, so I suggest sticking with Node.js.

    • @chisangamumba2961
      @chisangamumba2961 Рік тому

      Well, that's why you should create an Ajax Application. It ensures a complete separation of Client side code from Server-Side code. 🤷‍♂️

  • @fredpourlesintimes
    @fredpourlesintimes 2 роки тому +6

    It's weird : In your tutorial, you write .then((response) => { response.json() }) to get the redirection attribute, but it doesn't work - my side -, if I don't return response.json().
    Edit : apparently, it's because we use return only with curly brackets, otherwise we don't have to.
    Thanks for this really useful chapter.

    • @harshitkumar5875
      @harshitkumar5875 2 роки тому

      Thanks man !!
      wasted half an hour searching for the error 🥲🥲

    • @jeikashu
      @jeikashu Рік тому +4

      For future people, why it doesn't work is: with curly brackets we need to write 'return response.json()' because otherwise the code doesn't return anything and the next then() doesn't receive any data. Without the curly brackets, JS assumes that respone.json() is the return value for the then method, and we get the 'data'

  • @alearg89
    @alearg89 4 роки тому +6

    Thanks a lot! i am bit overwhelm since #9. I was coming along fine, i dont know what happend :( Anyone feeling the same?

    • @MrIshumaru
      @MrIshumaru 3 роки тому

      same, in the back of my head i'm just thinking, there has to be an easier way to do this with how far computing has come. taking notes and writing in the margins explaining what things do in your own words help

  • @jackfrost8969
    @jackfrost8969 4 роки тому +9

    If only you also had added the update part, that would have been so perfect.
    I wonder why you left it out though.

    • @erniea5843
      @erniea5843 3 роки тому +5

      so you can try to see if you can figure it out baed on the examples :). Not that hard with the GET & DELETE route examples. just use PUT the the applicable mongoose method. Best way to learn!

  • @mrmeinept
    @mrmeinept 2 роки тому +3

    That feeling when you spend 2 hours reading tutorials that aren't helpful and then find that one video who helps you in less than 30 minutes:

  • @mikoajpaszkowski2985
    @mikoajpaszkowski2985 4 роки тому +6

    I just LOVE that moment when I need to pause the video to say: "Ahaaaaaaaaaaaaa, it's amazing!"

    • @NetNinja
      @NetNinja  4 роки тому +1

      Thank you so much!!

  • @RonWaller
    @RonWaller 2 роки тому +2

    You keep mentioning that "this is asynchronous". How do you know when "something" is asynchronous or not? Is it documented somewhere? Also, you are using .then() syntax. How would you use async/await with this? Thanks

    • @programwithviggo2197
      @programwithviggo2197 2 роки тому

      You can check the documentation to see if it's asynchronous or returns a promise. If you're using VS Code try and hover over it and see if it'll give you such information.

  • @spacecorp2000
    @spacecorp2000 2 роки тому +2

    Why are we NOT updating a document ?

  • @rajithasri8426
    @rajithasri8426 4 роки тому +4

    Hello sir, can u make MERN stack courese?

  • @johnnychang3456
    @johnnychang3456 4 роки тому +4

    Not sure if anyone has the same issue: id = req.params.id returns a string with space at front. It leads to error when Blog.findById(id).
    I have to trim() id to get the desired result: const id = req.params.id.trim()
    I resolved the issue, but I have no idea why it's happening... anyone??

    • @danyalsajid123
      @danyalsajid123 3 роки тому

      Yes i got the same issue. Thanks for the solution btw.

    • @shanetravel
      @shanetravel 3 роки тому

      yeah i got the same issue. thank you for this.

    • @toluolawumi3288
      @toluolawumi3288 3 роки тому

      Thanks for this solution, ran into it now also

    • @spiderduckpig
      @spiderduckpig 3 роки тому

      I have the same problem, thanks for the solution

    • @divsyntax9720
      @divsyntax9720 Рік тому

      I had to use this.... '/blogs/:id([0-9a-fA-F]{24})'; 🤷‍♂

  • @risechess7114
    @risechess7114 2 роки тому +1

    the delete thing didnot work and the problem is i dont see the error thing in console wtf........ i dont fking understand why 1000000 step for just delete thing ????!!!!!!!!!!!! is this what really delete takes ??? and help someone facing same problem

  • @DylanL9
    @DylanL9 4 роки тому +2

    Do you think you can create a tutorial about using node-fetch and creating a project where you would use a stock API for example?

  • @alrikmessner196
    @alrikmessner196 7 місяців тому

    When you did href="/styles.css" without the slash, everything works until you want the blog details...And then a GET /blogs/styles.css happens. When you miss the logged additional GET, you just wonder, how the following stack trace could happen 😅

  • @ericpodhorecki5427
    @ericpodhorecki5427 3 роки тому +7

    best node course online from far. Amazing work!!

    • @NetNinja
      @NetNinja  3 роки тому +1

      Thanks so much :)

  • @leonardoxavier4114
    @leonardoxavier4114 Рік тому +2

    Hi gang! I have an error: min 31:57
    SyntaxError: Unexpected token '

    • @connorphillips304
      @connorphillips304 Рік тому +1

      Same error here... Also would love to finish the course :(

    • @parv69
      @parv69 Рік тому

      did u find solution ? i m stuck

    • @macgruber1920
      @macgruber1920 4 місяці тому

      @@parv69 I was having the same issue, and removing 'blogs' from endpoint solved it. It was trying to redirect to /blogs/blogs/asdfnasodifj so now I just have:
      const endpoint = `${trashcan.dataset.doc}
      and that fixed it for me, hope that helps!

  • @malcolmcolindixon
    @malcolmcolindixon 4 роки тому +4

    Great work as always Shaun, just completed your Udemy modern Javascript course a few days ago and then started this series, it's all coming together now. Would really like to see working with Postgresql sometime, I'm sure it's similar concepts to this though.

  • @alisonmaciel314
    @alisonmaciel314 3 роки тому +2

    I've been stuck for almost a day on post request, didn't know what I was doing wrong and nothing seems to help with my problem. Came here and in less than 10 minutes you already saved me with the "express.urlencoded" tip, ty!

  • @MuhammadZubair-co5jl
    @MuhammadZubair-co5jl 3 роки тому +4

    Greate videos (Thank you )
    Sir, It can be also done by putting a (href) property in a(anchor tag)and set it value to '/blogs', without redirecting to the blogs page using JSON (lots of steps involves).

    • @condensedmatter118
      @condensedmatter118 3 роки тому

      Underrated comment. Not sure why he did it that way but this is ALOT easier.

  • @mikegogl
    @mikegogl 3 роки тому

    Thanks man you are fantastic. I am learning a lot. Honestly, thank you!

  • @cyrusharoon85
    @cyrusharoon85 4 роки тому +1

    Sir, please make Node bootcamp with ecommerce and React with Redux ecommerce on udemy paid courses. You are an awesome instructor.

  • @darpananeja4751
    @darpananeja4751 3 роки тому

    Beautiful course!!! Amazing satisfaction!

  • @kopilkaiser8991
    @kopilkaiser8991 4 місяці тому +1

    Brilliant tutorial. I've learnt quite a lot from watching this. I would highly recommend all to watch this excellent informative and simple node.js crash course 😊🤝
    You are a brilliant and exceptionally great teacher. Being able to convey your knowledge by explaining patiently.

    • @NetNinja
      @NetNinja  4 місяці тому

      That means a lot, thank you so much :)

  • @silfion2395
    @silfion2395 Рік тому

    Great tutorial, is there an example of put request with this type of logic?

  • @fakefaker1564
    @fakefaker1564 4 роки тому +1

    Is there any body got problem... when press delete button..
    something like this.. (404 error not find)
    DELETE /blogs/5f8ea86ffe635721782282a8 404 1.700 ms - 696
    Thanks

    • @andriykuts1981
      @andriykuts1981 3 роки тому +1

      i had something similar when i tried to redirect directly from
      Blog.findByIdAndDelete(id)
      .then((result) => {
      res.redirect('/blogs')
      Or maybe you have some issue with id, and mongoose cant find it in DB

  • @martinsmifff
    @martinsmifff 4 роки тому +5

    Hi Shaun, again a great tutorial. Did you know about the express middleware "method-override", is is quite neat because it allows you to simulate DELETE and PUT requests using the normal form, with just a hidden field. Tis would simply things a great deal as you wouldn't need to use the JavaScript.

  • @sebastianmyrcha1034
    @sebastianmyrcha1034 3 роки тому +1

    I am also a big fan of all of your courses.
    But I am not experienced and a little bit confused.
    After the Vue course I thought that the standard is to use frontend app in framework like VEU, and some backend app which REST API serving data in JSON format.
    After this course I am not sure, because there is a different solution.
    So which solution is better, and why.
    1) Rest API with express.js and Mongo DB, and frontend application with VUE
    2) Backend serving html pages with EJS view engine

  • @maheshnavoor
    @maheshnavoor 2 роки тому +1

    Please help me
    I got error in delete operation
    When click delete in console show
    "Unexpected token '

    • @parv69
      @parv69 Рік тому

      did u find any sol!! i am stuck

  • @kurokurovich
    @kurokurovich 3 роки тому +5

    the route /blogs/create needs to be above the routes that you pass parameters

    • @MagicOfNorway123
      @MagicOfNorway123 2 роки тому

      Wow, been struggling with this for an hour. Thanks, that fixed it immediately!

    • @siomarapantarotto
      @siomarapantarotto Рік тому

      I was wondering why the app that was working fine suddenly presented an error 2 days later and your post fixed the problem. Many thanks. 👋

  • @SENPAI-mi6sz
    @SENPAI-mi6sz 3 роки тому +1

    what vscode theme you are using?
    and if u have time pls make a video about some useful vscode extensions. and ty so much for those courses

  • @zakhariihusar6975
    @zakhariihusar6975 10 місяців тому +1

    I have a question about those dynamic routes like /blogs/:id . What happens if you past incorrect id? Then your code will try to find incorrect id in the DB and throw an error? And then you'd handle that error by redirecting to 404? Do I understand correctly? Coz I used to struggle with React Router while trying to implement routing only on the front end...

  • @omarkouta9720
    @omarkouta9720 3 роки тому +1

    I used another way to delete a blog...
    1- clicking on the delete link in the details screen.
    2- it deletes the blog from database with "FindbyIdanddelete(id)".
    3- redirect to the main page ('/blogs').
    And it works, but I don't know if it is okay or not. May be there is a problem I didn't notice.
    Please tell me Shaun if there is any problem in this way.

  • @zachfenton608
    @zachfenton608 2 роки тому +1

    I get the following problem: failed to cast the delete request. GET /blogs/%206279dfb4df4706663b6b4f3c 200 41.678 ms - 2925
    CastError: Cast to ObjectId failed for value "$(trashcan.dataset.doc)" (type string) at path "_id" for model "Blog"
    s
    ode-crash-course
    ode_server
    ode_modules\mongoose\lib\query.js:5137:12),
    valueType: 'string'
    }

  • @papadong
    @papadong 4 роки тому

    Nice tutorial as always. Thank you

  • @rodo200__
    @rodo200__ 4 роки тому +2

    podrias hacer un curso completo de stack MEVN de Javascript y con estilos de Vuetify seria excelente

  • @IAmSamuelCharpentier
    @IAmSamuelCharpentier 4 роки тому +2

    I think is should be
    const endpoint = `/blogs/${e.target.dataset.doc}`;
    in case there's mode than one 'a.delete' elements on the page 🤷🏻‍♂️

  • @CySA28
    @CySA28 3 роки тому +1

    In detail.ejs when i send delete request i've got this error at the line 7:
    5|
    6|
    >> 7|
    8|
    9|
    10|
    Cannot read property 'title' of null

    • @venndi8867
      @venndi8867 2 роки тому +1

      Old question, but if somebody need a solution, here it is. I have just deleted a the href attribute by the delete button in the details ejs, which was created automatically when you press "a" and then enter.

    • @nightcrawler6618
      @nightcrawler6618 2 роки тому

      @@venndi8867 OMG, I spent way to much time trying resolve the same error. How did you even figure this out?
      Anyways that helped. Thanks!

  • @rashidiqbal6810
    @rashidiqbal6810 2 роки тому +1

    SyntaxError: Unexpected token < in JSON at position 0 cant delete (json)

  • @matthew78uk
    @matthew78uk 4 роки тому +2

    So much content in a single video! All the basics of CR(U)D, organised and explained very well! Many Thanks indeed!

  • @_rahiali
    @_rahiali 4 роки тому +2

    everything was working fine till the end but now idk what when I go to create.ejs it cannot load the css file. I get a long error but starts with Cast to ObjectId failed for value "style.css" at path "_id" for model "Blog". it only happens on create.ejs all other pages load the css fine
    any idea?

    • @_rahiali
      @_rahiali 4 роки тому

      why does create and detail urls are blogs/create and blogs/detail we don't even have that directory

    • @ДмитрийМузыченко-д5ш
      @ДмитрийМузыченко-д5ш 3 роки тому +5

      I had a similar mistake. Then i changed a link from "styles.css" to "/styles.css" and it started working fine.

    • @sohump7904
      @sohump7904 3 роки тому

      @@ДмитрийМузыченко-д5ш thank you so much I was stuck on this problem for a long time

    • @aengtech
      @aengtech 3 роки тому

      @@ДмитрийМузыченко-д5ш I've been scrolling for this comment for over an hour now. Thank you for this. This forward slash has caused more damage to my code than any other error. Thanks again

    • @sulaimang5517
      @sulaimang5517 3 роки тому

      @@ДмитрийМузыченко-д5ш thank you very much

  • @bencepandi3568
    @bencepandi3568 4 роки тому +1

    Any idea why do I get "undefined" when I try to console log the id? I have express, bodyParser, everything set properly.

  • @codedynamics1
    @codedynamics1 3 роки тому +1

    @netninja how excited you get when something works 😂👨‍💻 love it!!😂

  • @kaebogtimater
    @kaebogtimater 2 роки тому +1

    please help, after following the delete request, the create new doesent work anymore, it hangs, and this error on terminal:
    messageFormat: undefined,
    stringValue: '"create"',
    kind: 'ObjectId',
    value: 'create',
    path: '_id',
    reason: BSONTypeError: Argument passed in must be a string of
    12 bytes or a string of 24 hex characters

    • @kaebogtimater
      @kaebogtimater 2 роки тому +1

      ok after reading the comments i realized:
      the route /blogs/create needs to be above the routes that you pass parameters

    • @Blenberg
      @Blenberg 2 роки тому +2

      @@kaebogtimater doesn't work

    • @kaebogtimater
      @kaebogtimater 2 роки тому

      @@Blenberg it works bro

  • @segafrompk
    @segafrompk 4 роки тому +3

    Hey Shaun, how does node distinguish between /blogs/:id and /blogs/create request? Since id is not defined as an number, wouldn't it try to find blog with an ID of "create" and fail?

    • @NetNinja
      @NetNinja  4 роки тому +2

      You are correct - the create route should be below the :id route :)

    • @longnt7375
      @longnt7375 4 роки тому +5

      @@NetNinja I think the create route should be above the :id route :)
      // blog routes
      app.get('/blogs/create', (req,res) => {
      res.render('create', {title: 'Create a new blog'});
      });
      app.get('/blogs', (req,res) => {
      Blog.find().sort({ createdAt: -1 })
      .then((result) => {
      res.render('index', {title: 'All Blogs', blogs: result})
      })
      .catch((err) => {
      console.log(err);
      });
      });
      app.post('/blogs', (req,res) => {
      const blog = new Blog(req.body);
      blog.save()
      .then((result) => {
      res.redirect('/blogs');
      })
      .catch((err) => {
      console.log(err);
      });
      });
      app.get('/blogs/:id', (req,res) => {
      const id = req.params.id;
      Blog.findById(id)
      .then((result) => {
      res.render('details', { blog: result, title: 'Blog Details' })
      })
      .catch((err) => {
      console.log(err);
      });
      });
      app.delete('/blogs/:id', (req,res) => {
      const id = req.params.id;
      Blog.findByIdAndDelete(id)
      .then((result) => {
      res.json({ redirect: '/blogs' })
      })
      .catch((err) => {
      console.log(err);
      });
      });

    • @srichandrasiripuram4724
      @srichandrasiripuram4724 3 роки тому +3

      @@longnt7375 thanks dude u helped me out of this error. I wasted 2hrs searching for what happened

    • @darkmojojojo
      @darkmojojojo 2 роки тому

      I just ran into this error and moving app.get('/blogs/create' ...) above both app.get('/blogs/:id' ...) and app.delete('/blogs/:id' ...) seems to fix it.

    • @parv69
      @parv69 Рік тому

      @@srichandrasiripuram4724 same bro T-T

  • @shadmanmartinpiyal4057
    @shadmanmartinpiyal4057 4 роки тому +2

    Please do a full MERN Stack course.

  • @priyadarsimishra7909
    @priyadarsimishra7909 4 роки тому +1

    Awesome Video 👍, can you make a firebase/firestore + react native app

  • @technoultimategaming2999
    @technoultimategaming2999 2 роки тому +1

    dude your back must hurt from carrying my whole grade

  • @muhammadjunaid2329
    @muhammadjunaid2329 3 роки тому +1

    But it adds event listener on the very first [a.delete]. How I can fix it?

  • @bigshuff
    @bigshuff 15 днів тому

    Nearing the end of the course now and have build the same project on my own computer along with you. Although I also watched the Mongodb course on Compass and used used compass instead of the cloud. I have to say your knowledge of the subject and your amazing ability to teach the subject line by line as you go absolutely blows my mind, I honest don't know how you do it. I don't think I know how to do ANYTHING as well as you do this. Thank you most sincerely.

  • @tolakanofficial1565
    @tolakanofficial1565 Рік тому

    Can you show how to update the data?
    Because I can’t get the data after I submit it. (PUT method)
    Thank you in advance.

  • @talhayerlikaya5199
    @talhayerlikaya5199 3 роки тому +1

    when you download course to github ?
    İ have an issue and cant fix it

  • @dayakarmaisa
    @dayakarmaisa 6 місяців тому

    @19:14 somebody Please help when i click on a single blog, the browser keeps loading forever even though I wrote '/blogs/create' above '/blogs/create/:id' :
    CastError: Cast to ObjectId failed for value " 660921cd72139f76c407bf88" (type string) at path "_id" for model "Blog"

  • @lestercute892
    @lestercute892 4 роки тому +2

    I don't understand why did you have to go through all those work on making a delete request.
    Why not just use a form tags and pass the post id on the url?

    • @sameerchoubey9724
      @sameerchoubey9724 4 роки тому

      Because he is using Ajax and it's dynamic.

    • @andriykuts1981
      @andriykuts1981 3 роки тому

      or through input type='hidden" and then get it from req.body

  • @bartoszsowa5140
    @bartoszsowa5140 2 роки тому +2

    Can anybody explain me why when I type in fetch in details.ejs " .then((response) => response.json() ) " it works, but when i type ".then((response) => { response.json() })" (with curly braces), then I get an undefined error? Like the curly braces were forbidden just in this one case...

    • @SeeRjED
      @SeeRjED 2 роки тому +4

      Old comment now but in case someone else finds this you need to use the return keywork when using curly braces. Without curly braces the return is implicit.

  • @muskaan7895
    @muskaan7895 3 роки тому +1

    The only part which I found a little difficult 😬 especially that delete.

  • @xtan-yt
    @xtan-yt 9 місяців тому

    35:37 Hey why not just make a post request and pass the id, then delete it from the db, we can also redirect easly with that. is this DELETE request important ? like this , app.post('/delete/:id',(req,res)=>Model.findByIdAndDelete....)

  • @vladimirputindreadlockrast812

    I think I lost my way. My page shows, in plain text: "Home Your path to becoming a Node.js ninja!"
    I CTRL C to stop Node, download and paste Lesson 10 into node-crash-course, type nodemon tuts in my terminal, but the webpage still has the text and style from one of the earlier lessons. Doesn't look anything like the output in this lesson. *UPDATE:* Not sure which lesson I got "nodemon tuts" command from, but I stopped the server, then typed "node app" and now my blog is looking correct again.

  • @bacgon6928
    @bacgon6928 3 роки тому +1

    If you got error: CastError: Cast to ObjectId failed for value "undefined"
    It might because your code : const endpoint = `/blogs/${trash.dataset.storeid}`; endpoint is not defined
    Solution is when you named your custom attribute : data-storeid=""
    where data-XXX cannot have any capital letter
    I should just named doc. So I won't get this error. LOL

    • @nhanNguyen-wo8fy
      @nhanNguyen-wo8fy 3 роки тому

      I used "doc" but still I have this error
      CastError: Cast to ObjectId failed for value "${trashcan.dataset.doc}" at path "_id" for model "tasks"

  • @andromilk2634
    @andromilk2634 6 місяців тому

    There was something which I was wondering when you create your request types : instead of using the name /blogs for a POST request, so the same as /blogs for a GET request, I assume that could you have picked any other term for this POST request instead and it would have worked without any problem?

  • @visualismanformuslims673
    @visualismanformuslims673 3 роки тому +1

    Ever best explaining,
    You are a great teacher, may Allah bless you. 😇

  • @evilservo
    @evilservo 4 роки тому +1

    IS there not an express.js delete method like get and post?

  • @solo-yl8uc
    @solo-yl8uc 3 роки тому +1

    Can I ask what theme of code is that you used? Your code color is much better than mine. I want to set it up like you !
    e.g. it's only red highlight at the first "

    • @dofa1111
      @dofa1111 2 роки тому

      did you figure out what theme?

  • @therichardchannel
    @therichardchannel 3 роки тому +1

    I can't get the redirect to work after the delete request. I get "TypeError: Cannot read property 'redirect' of undefined" in the console, it seems that the data in the second .then() chain won't get recognize as the same 'data' as the parameter for some reason. Anyone know why?

    • @kumar_nikhil
      @kumar_nikhil 3 роки тому +6

      If you're using curly braces then you need to use return keyword. Then you will be able to redirect.
      fetch(endpoint, {
      method: 'DELETE'
      })
      .then((response) => {
      return response.json();
      })
      .then((data) => {
      window.location.href = data.redirect;
      })
      .catch((err) => {
      console.log(err);
      })

  • @RegishShrestha
    @RegishShrestha Рік тому

    I have been getting this error:
    CastError: Cast to ObjectId failed for value "style1.css" (type string) at path "_id" for model "Blog"
    Can someone help me ?

  • @SPLUGA
    @SPLUGA 2 місяці тому

    the app.post('/blogs'...) shouldn't it run upon the case '/blogs/create'... ie app.post('/blogs/create'...) ?

  • @taqikhan5418
    @taqikhan5418 2 роки тому

    CastError: Cast to ObjectId failed for value "style.css" (type string) at path "_id" for model "Blog"
    I am getting this error please please guide

  • @AccessCode101
    @AccessCode101 4 роки тому +1

    Quick question: This is server side rendering, right? If I wanted to use this same project and use react, the only best thing that's going to help me is react router, right?

    • @MartonDev
      @MartonDev 4 роки тому +3

      yeah, this is serverside rendering. you should probably make raw json responses instead of rendering and then using axios or some kind of https request module to connect the front-end with it

  • @johnpzaccari
    @johnpzaccari 3 роки тому

    You are the freaking man!!!!!

  • @karanraghuwanshi8563
    @karanraghuwanshi8563 Рік тому

    my css doesn't work wherever there is /blogs/... and shows error of styles.css not found
    when i change it to just /... it works fine
    can someone help

  • @igwennaemeka6006
    @igwennaemeka6006 2 роки тому

    nice job mr net ninja , but honestly speaking I've been trying this delete request on my app but its not working and I'm really depressed right now

  • @LucXX36
    @LucXX36 4 роки тому +2

    Great, like always. Thank you! This whole course is such a nice refreshing

  • @shilpadolai4228
    @shilpadolai4228 6 місяців тому

    @23:31 can we not use href directly with the delete button providing the id in the url just like we did for the details page. that way we dont have to write evrything we wrote in the script tag??

  • @inspiredomkar1239
    @inspiredomkar1239 5 місяців тому

    Rather than using then and catch we can simply make use of await. Not using await is unnecessarily increasing number of lines.

  • @Blenberg
    @Blenberg 2 роки тому

    Could you help me.
    How can i add image to this blog?.
    I tried Multer,but i couldn't display image

  • @jyotiranjan_prusty
    @jyotiranjan_prusty Рік тому

    title: CastError: Cast to string failed for value (type Array) at path "title" Can someone say about this?

  • @BlackTgaming
    @BlackTgaming 3 роки тому

    Anyone else seeing this error TypeError: Cannot read property 'redirect' of undefined
    at 6081b36163c98234700dfc8c:50

  • @tannerbarcelos6880
    @tannerbarcelos6880 4 роки тому +4

    Was trying to do MERN stuff before really getting my node, express and mongodb core skills down. Realized I was just copying tutorials and not learning.
    I am gonna watch this whole series and learn a ton. Just from laying here watching this, I understood everything from past knowledge or just good JavaScript skills and it’s exciting because I’m really trying to learn fullstack development while also learning it in school academically.
    Thank you for all your videos brother !

  • @LubieArbuzy
    @LubieArbuzy 4 роки тому +3

    Great content as always!

  • @neahnderthal
    @neahnderthal 3 роки тому +1

    15:47 he said deez nuts. absolute madman

  • @diegoavendanohernandez9908
    @diegoavendanohernandez9908 4 місяці тому

    It shouldn't be something important I guess but I like your accent haha

  • @bhumijain271
    @bhumijain271 Місяць тому

    im getting error in delete one udefined type i dont know what to do i use all methods pls hepl if any one can

  • @andriykuts1981
    @andriykuts1981 3 роки тому

    Is it a good idea to use something like
    app.post("/blogs/delete/:id", (req, res) => {
    const id = req.params.id;
    Blog.findByIdAndDelete(id)
    .then((result) => {
    res.redirect("/blogs");
    })
    .catch((err) => {
    console.log(err);
    });
    });
    and
    Delete

  • @Ard1023
    @Ard1023 8 місяців тому

    this becomes too complicated.
    can you make without any other libraries.

  • @fatmaelhosary6875
    @fatmaelhosary6875 4 роки тому

    i get an error when i want to open create route after i have deleted all blogs ?
    at C:\Users\Fatma\Desktop
    odeJS
    ode_modules\express\lib
    outer\index.js:284:7 {
    messageFormat: undefined,
    stringValue: '"create"',
    kind: 'ObjectId',
    value: 'create',
    path: '_id',
    reason: Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters

  • @elpheno
    @elpheno 4 роки тому +1

    This session was more difficult for me; I 'll try again later.
    Thank you Boss

  • @hassanelwany560
    @hassanelwany560 2 роки тому

    Hi,
    I am trying to get attribute values, when i tested it with
    console.log(req.body)
    it return title value, snippet value, but it didn't back with body value
    may I ask for help?

  • @thatsalot3577
    @thatsalot3577 2 роки тому

    Hey, I was having sort of an error when I defined the app.get('/blogs/:id') before app.get('/blogs/create') as for no reason it was treating 'create' as an id
    however it works when I define the blogs/create above.

  • @daliusbeckjr.3918
    @daliusbeckjr.3918 Рік тому

    is there an example of making an update route path. I don't know if I am on the right track with the one I made.
    nevermind :D I just figured out how to do an update method for my crud application. also thank you for the course. You are literally one of my top sources to go to when I am interested in learning more for the frontend in my full stack journey.

  • @ebiscaia
    @ebiscaia 2 роки тому

    Hi mate,
    How could I use the contents of a div with the contenteditable="true" instead of a textarea? I would like to put a WYSIWYG app in there, but it always crash.
    Cheers,

  • @grandwizardnoticer8975
    @grandwizardnoticer8975 4 роки тому

    How do we PUT, or otherwise edit and save an existing blog post?
    I have:
    * created an 'edit.ejs' based on 'create,' but with all textareas in the form.
    * put it in a sub dir to distinguish it from others for sake of the router.
    * added button to the details page that direct-links to edit.ejs:
    * used all textareas in form to get full, editable text back into form
    So the problem is that it currently creates a new, edited version of the original blog.
    What's the best way of getting it to update rather than create a new blog? Thanks!