SHARE

Hey gang, in this REST API tutorial I’ll show you how to connect to MongoDB from our code, and how to save new data to our collection when we receive a POST request.

—– COURSE LINKS:
+ Repo – https://github.com/iamshaunjp/rest-api-playlist
+ Atom editor – https://atom.io/a
+ Download GIT – https://git-scm.com/
+ Node.js for Beginners Playlist –
https://www.youtube.com/playlist?list=PL4cUxeGkcC9gcy9lrvMJ75z9maRw4byYp
+ MongoDB playlist – https://www.youtube.com/playlist?list=PL4cUxeGkcC9jpvoYriLI0bY8DOgWZfi6u

———————————————————————————————
You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress, Node.js & more on the channel homepage…

SUBSCRIBE TO CHANNEL – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

========== PSD to WordPress Playlist ==========

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gnow7e45LQFkNVxwQ5BH-W

============ Node.js for Beginners Playlist =============

https://www.youtube.com/playlist?list=PL4cUxeGkcC9gcy9lrvMJ75z9maRw4byYp

============== The Net Ninja =====================

For more front-end development tutorials & to black-belt your coding skills, head over to – https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg or http://thenetninja.co.uk

================== Social Links ==================

Twitter – @TheNetNinja – https://twitter.com/thenetninjauk

21 COMMENTS

  1. pls, i got this error when i was trying to connect to mongodb: $ nodemon index
    [nodemon] 1.12.1
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching: .
    [nodemon] starting `node index index.js`
    events.js:160
    throw er; // Unhandled 'error' event
    ^

    Error: listen EADDRINUSE :::4000
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at Server._listen2 (net.js:1259:14)
    at listen (net.js:1295:10)
    at Server.listen (net.js:1391:5)
    at EventEmitter.listen (C:xampphtdocsrest-api-playlistnode_modulesexpresslibapplication.js:618:24)
    at Object.<anonymous> (C:xampphtdocsrest-api-playlistindex.js:22:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
    [nodemon] app crashed – waiting for file changes before starting…

    pls help me

  2. Really fun this, I faced error>> MongoError: connection 0 to localhost:4000 closed.
    And after change port on db connection to 27017, its running now

  3. If you are using moongoose 4.11.0, try to connect to the database using this chunk:
    mongoose.connect('mongoDb://localhost/ninjago', { useMongoClient: true });

  4. IDK what my code did wrong. When i run the post. it keep get hang. anyone have any idea why?. Post man keep in sending mode and with "Loading…" display the bot bottom
    PS : i even pull the git repo and make it run. same thing happen. i can get and other, but cant post. I think maybe st wrong with how i setup the database. Which video is on the MongoDB setup again?

  5. My error is "DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is dep
    recated", Who do i solve this?

  6. For those on a Mac, if you have it set up properly, just run " mongod " to start the mongo dameon. You don't have to supply a file path or anything else; just " mongod ".

  7. When i tried to post the request using Postman data i got an error "Name field is required"
    ———————————————————————————————————————————————-
    node index.js
    Now listening for requests…

    (node:9212) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ValidationError: Name field is required
    (node:9212) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

    Below is the json object i am sending using Postman as shown in the video:
    {
    "name":"ryu",
    "rank":"black belt",
    "available":true
    }

LEAVE A REPLY

Please enter your comment!
Please enter your name here