REST API Tutorial (Node, Express & Mongo) #6 - Creating Routes

Поделиться
HTML-код
  • Опубликовано: 3 окт 2024

Комментарии • 88

  • @gigantic-hyphen1118
    @gigantic-hyphen1118 7 лет назад +4

    These videos have helped me more than my teacher has. Thank you so much for these lessons. Keep up the great work!

  • @nileshkharat1188
    @nileshkharat1188 4 года назад

    i have no words........!!what a series // Awesome Awesome Awesome!!!!!

  • @Vignum
    @Vignum 3 года назад

    Hours of mumbo jumbo from a teacher, explained in 12m of complete excellence xD

  • @vahid6418
    @vahid6418 3 года назад +1

    Excellent course, thanks for providing us such beautiful contents Shaun !

  • @maskman4821
    @maskman4821 6 лет назад

    The best rest api tutorial series!!! The Net Ninja is awesome!!!

  • @AjaySingh-rq5yz
    @AjaySingh-rq5yz 7 лет назад +3

    Everthing " Makes Sense " .
    Greate job !

  • @BarryMarkGee
    @BarryMarkGee 7 лет назад +2

    Very well explained series. Thanks.

  • @manuelm.8364
    @manuelm.8364 7 лет назад +4

    Hello. This is a very good series. Thank you!
    In Ubuntu 16 I had to install nodemon globally to work (with parameter -g):
    npm install nodemon -g --save-dev

    • @SourceCodeDeleted
      @SourceCodeDeleted 7 лет назад +1

      If you don't have nodemon in path and it's not being found. Then you can run it from the node_modules folder.... I have node in path , but nothing else.
      like so:
      node node_modules/nodemon/bin/nodemon index

    • @thisguyistoofly
      @thisguyistoofly 6 лет назад +4

      No reason to save dev for global npm installs, doesn't do anything. If running locally you could do "npx nodemon" and it will magically work

    • @ferds001
      @ferds001 6 лет назад

      Very helpful thanks mate. For those that don't understand npx, it's just a replacement to run packages in your node_modules when it's not installed globally. As thisguyistoofly advised, its encouraged to not install it globally.

  • @-alfeim2919
    @-alfeim2919 3 года назад +1

    for any of you who get '-nodemon' is not recognized as an internal or external command,
    operable program or batch file. try npm install -g nodemon first

  • @Rahul-Nalawade
    @Rahul-Nalawade 5 лет назад +11

    at 0:45
    Instead of
    $ npm install nodemon --save-dev
    I had to use
    $ npm install -g nodemon
    Something others might have faced on Ubuntu 16.04 LTS.

    • @kevin-ru6oe
      @kevin-ru6oe 4 года назад

      I was going to comment the same. Thanks anyway

    • @suthirakprom
      @suthirakprom 4 года назад

      my window 10 machine also use this command instead of what Ninja’d mentioned.

  • @moderncloth682
    @moderncloth682 3 года назад

    My gawd... This is required reading for anyone curious about building with the ME_N stack....

  • @jennf8851
    @jennf8851 2 года назад

    This is awesome, thanks alot.

  • @ayyanchira
    @ayyanchira 6 лет назад

    Wonderfully explained! Thanks

  • @iandsouza9392
    @iandsouza9392 6 лет назад

    Great Series!! You're the best Thank you for making it so easy!

  • @nejmiify
    @nejmiify 5 лет назад

    Thank you very much! Very well explained!

  • @cheeseburger1884
    @cheeseburger1884 7 лет назад +16

    app.use('/api', routes);
    is way cleaner than
    app.use('/api', require('./routes/api.js'));
    I don't know why you decided to change that :p Awareness that u can do it maybe?

    • @Phrosen1
      @Phrosen1 6 лет назад +2

      Because there is no need to take up memory with a constant, if you're only going to use it once in the code. I agree that the first option looked cleaner, however.

    • @martinmtandi335
      @martinmtandi335 5 лет назад

      My thoughts too, so in my files i kept it the way it was... i didnt make the changes he made.

  • @vageeshak.m5996
    @vageeshak.m5996 6 лет назад

    very good vedio for beginners

  • @tomaszkonecki1038
    @tomaszkonecki1038 6 лет назад

    Great explanation. Thanks a lot!

  • @2011jiqbal
    @2011jiqbal 7 лет назад

    npm install -g nodemon --save-dev
    is also required on windows. some people have mentioned how its needed for ubuntu.

  • @anonmousse
    @anonmousse 7 лет назад

    Hey there, Thanks a ton for these videos! Frankly speaking, I haven't found much videos around in regards to NodeJS + ExpressJS that can explain in detail the way you do in a short 12:20 mins. Great great stuff!
    Now for my questions...I get the fact that we use app.use(routes); so that index can see api.js....But what advantage does app.use('/api', routes) give? Isn't it just extra typing to do so when localhost:3000/ninjas works perfectly?
    Thank you :) Keep up the amazing videos!

    • @NetNinja
      @NetNinja  7 лет назад +3

      Hey, good question. Using the express Router to split the routes is that we can make many different 'mini' apps, if you like. Yeah, we could use just /ninjas without using the router for the '/api/' section, but this way we could potentially have a /ninjas page which wasn't part of the api. Hope this makes sense.

    • @anonmousse
      @anonmousse 7 лет назад

      The Net Ninja. I see. Yes, that makes perfect sense. Thanks!

  • @someuser6005
    @someuser6005 7 лет назад +1

    Hello, thanks for great tut. As we require express in two seperate files are there two different express objects or are these two objects same and shared in both files? Is the program chaching the first express obj and using it in the second router file?

    • @someuser6005
      @someuser6005 7 лет назад +1

      well according to below link in es6 alltough you require same obj in seperate file it is the same object and it is called immutable binding.

  • @cedric_ds
    @cedric_ds 4 года назад

    I don't really understand why we have are working with 2 port numbers.
    Is 4000 the port number of the local server, where the website is hosted,
    and 27017 the port number of the local server, where the database is stored?

  • @satyamsinghal930
    @satyamsinghal930 6 лет назад

    a list of ninjas ! hahha .. you are really serious about being a ninja aren't u ?

  • @DheerajSharma-kt6df
    @DheerajSharma-kt6df 5 лет назад

    In the following tutorial of routes....url is same for get and post, put and delete...how to check the each case of route in browser

  • @zymawy
    @zymawy 7 лет назад

    جميل جدا شكرا لك

  • @cedric_ds
    @cedric_ds 4 года назад

    must app.listen be at the bottom of the file? does the order matter?

  • @jearbecerro1167
    @jearbecerro1167 4 года назад

    10:55 🤣

  • @letoan285
    @letoan285 7 лет назад

    Great Videos Bro, When you will release new ones?

  • @navinhiraskar2916
    @navinhiraskar2916 5 лет назад

    nice video. I want to do it on linux RHEL 7 (VM) and need to expose it for production. Need guidance

  • @marcosviniciuslimarodrigue5593
    @marcosviniciuslimarodrigue5593 6 лет назад

    Thank you for the tutorial!
    Quick question, though:
    I see that on the get method, you use
    router.get('/ninjas', function(req, res) {
    res.send({type: 'GET'})
    })
    Is there any particular problem in using an arrow function instead of the normal function for the HTTP methods?
    Like,
    router.get('/ninjas', (req, res) => {
    res.send({type: 'GET'})
    })
    I've see a lot of people using function over the arrow function for http methods, but as far as I tested there's no difference between the two of them. And arrow functions tend to look cleaner. So I'm just wondering why it seems to be preferred to use the normal function() for these methods.
    Thanks!

    • @HaBhBo
      @HaBhBo 6 лет назад

      interesting question.

    • @braedengendron6981
      @braedengendron6981 5 лет назад

      I believe it's just a stylistic choice. I always use arrow functions because they're easier to type and they look cleaner, and I've never had any issues specifically related to using them over the regular anonymous function syntax

  • @manavsaxena964
    @manavsaxena964 6 лет назад

    Hey Ninja, what's the advantage of using router.get() over app.get()? Why not create a new file and pass the app as parameter like in previous series?

    • @manavsaxena964
      @manavsaxena964 6 лет назад +2

      Nvm found it here: scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4

  • @H3000-v7i
    @H3000-v7i 7 лет назад

    When you use exports and then imports by require('/routes/api'). Can data flow both ways?

  • @muddassirahmed3342
    @muddassirahmed3342 7 лет назад +2

    Hi,
    Love your tuts, but im facing an error in this one.
    when i use "nodemon index" in cmd, it gives the following error :
    ''nodemon' is not recognized as an internal or external command,
    operable program or batch file.'
    Any help?

    • @wisnuaryadipa3501
      @wisnuaryadipa3501 7 лет назад +6

      you should instal nodemon globaly on your pc
      npm install -g nodemon --save-dev

    • @muddassirahmed3342
      @muddassirahmed3342 7 лет назад

      Wisnu Arya Dipa
      Then how does it work in the video without it?

    • @wisnuaryadipa3501
      @wisnuaryadipa3501 7 лет назад

      he already install nodemon globaly before he make this video tutorial.
      if you already doing -> "npm install nodemon -g" u just need to do "npm install nodemon --save-dev" every you create a project.
      --save-dev means you save to development dependency on package.json
      you can visit docs.npmjs.com/cli/install to get complete explanation about CLI command especially install command

    • @jeromehurley2033
      @jeromehurley2033 7 лет назад

      npm install -g nodemon --save-dev
      followed by
      npm install nodemon --save-dev
      Worked for me.....thanks peeps

    • @thisguyistoofly
      @thisguyistoofly 6 лет назад

      "npx nodemon"

  • @prathamkesarkar
    @prathamkesarkar 7 лет назад

    are you going to cover rest api using https package

  • @emiljager2914
    @emiljager2914 7 лет назад +4

    TypeError: app.use() requires middleware functions
    What is the issue here?

    • @KarDiamond
      @KarDiamond 7 лет назад +17

      Might have done the same mistake as me.
      I wrote export, and not exports in the api.js file.
      module.exports = router;
      And I had the same error as you.

    • @emiljager2914
      @emiljager2914 7 лет назад +1

      Thanks man!

    • @LewesMint
      @LewesMint 7 лет назад +1

      i made exactly the same mistake
      =

    • @danielkanyo9417
      @danielkanyo9417 7 лет назад +1

      Thank you!

    • @surajradhakrishnan3617
      @surajradhakrishnan3617 5 лет назад +1

      @@KarDiamond haha i made the same mistake. thanks

  • @mohamedsadid8403
    @mohamedsadid8403 7 лет назад +1

    why don't I use just app.get for the whole routing instead of using route.get and so ... ?

    • @Rassy_
      @Rassy_ 7 лет назад +1

      For organization, also for larger projects we would need to use a separate file for our routes,instead of cluttering our index.js with all the code

    • @manavsaxena964
      @manavsaxena964 6 лет назад

      but we could have used a separate file and passed the app as a parameter and used app.get instead

    • @HaBhBo
      @HaBhBo 6 лет назад

      this is a good read on why u should start using this.
      scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4

  • @mikkel1
    @mikkel1 7 лет назад

    It says cannot get...

  • @sitiaisyahazman6565
    @sitiaisyahazman6565 5 лет назад

    is it '/ninjas' in a folder ??

  • @Urethrify
    @Urethrify 7 лет назад

    Your tutorial is 11:07 :)

  • @moreshwardalavi
    @moreshwardalavi 7 лет назад +1

    Hello, first of all thanks for this series..
    I'm facing one problem regarding nodemon command on my PC it shows me following error..
    ------------------------------------------------------------------------------------------------------
    λ nodemon index
    'nodemon' is not recognized as an internal or external command,
    operable program or batch file.
    ------------------------------------------------------------------------------------------------------
    what should I do?

    • @yuqiu2098
      @yuqiu2098 7 лет назад +8

      in package.json, add a new line in "scripts" like this:
      ----------------------------
      "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "serve": "nodemon index.js"
      },
      run like this:
      -------------------------
      npm run serve

    • @moreshwardalavi
      @moreshwardalavi 7 лет назад

      Wohoo!.. It Works!!
      Thank you ;)

    • @froggerabc
      @froggerabc 7 лет назад +1

      nice one thanks!

    • @this.channel
      @this.channel 7 лет назад +1

      Thanks, it worked. I think the reason for it not working is something to do with the $PATH variable.

    • @zymawy
      @zymawy 7 лет назад +1

      What I Just Did Is reinstall the nodemon again but globally with this commend
      npm install nodemon -g --save-dev

  • @palkondatharun5064
    @palkondatharun5064 5 лет назад

    nodemon package is installed but if i executed
    nodemon index means it is showing the error as nodemon is not an a internal or external command
    please help what i need to do

    • @martinmtandi335
      @martinmtandi335 5 лет назад

      try running it inside of your project files, because thats where you installed your nodemon modules. Hope that will solve your problem

  • @karthick28696
    @karthick28696 7 лет назад

    nodemon didn't work on ubuntu, even 'npm install nodemon -g' didn't help

  • @golcuk2076
    @golcuk2076 2 года назад

    why do u publish those videos free instead of selling

  • @sitiaisyahazman6565
    @sitiaisyahazman6565 5 лет назад

    when i type nodemon index in cmd, they said "nodemon'' is not recognized as an internal or external command, operable program or batch file. I already install nodemon --save-dev. What are the solution ?

    • @martinmtandi335
      @martinmtandi335 5 лет назад

      am going to assume you ran that command outside of your project files.

    • @unity_with_timoteo
      @unity_with_timoteo 4 года назад

      make it global: npm install -g nodemon

  • @horizoncoding_
    @horizoncoding_ 6 лет назад

    someone can explain me how app.use('/api', require('./routes/api.js')); influence the code. If I understand well the request of user reach firstly app.js, wich handle the routes taken by the user request. But I can't definitely understand how this snippet works.
    Someone can explain me what the function app.use('/api', require('./routes/api.js')); does step by step please ?
    Kind regard

    • @sayhiprasad
      @sayhiprasad 5 лет назад

      @Horizon Coding, Here is the explanation
      app.use('/api', require('./routes/api.js')) basically tells server that if you get request for '/api' then please use the file located under './routes/api.js' .
      And /routes/api.js file will have get/post/put/delete request inside it.