VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Build a Node.js API - tutorial

Build a Node.js API - tutorial

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Create basic CRUD routes with Node.js, Express, and MongoDB. NOTE: For this to work correctly, you must use the same version of mongodb. Your package.json file should say: mongodb: -2.2.33 - Code on GitHub: https://github.com/beaucarnes/fcc-project-tutorials/tree/master/notable - Based on this article by Scott Domes: https://medium.freecodecamp.org/building-a-simple-node-js-api-in-under-30-minutes-a07ea9e390d2 - Beau Carnes on
Date: 2022-03-14

Comments and reviews: 10


22:30 at that point I get the error -db.collection is not a function-. It seems a few things are different with MongoDB Atlas, since mLab doesn't work as presented in the video anymore.
What I needed to do was follow the instructions of MongoDB Atlas to set everything up, then go to Clusters, my created cluster, click 'Connect' > 'Connect Your Application', there's a) the URL we need and, when clicking 'Full Driver Example', I can see why I receive the above error message. With this it seems to work:
const client = new MongoClient(db.url, - useNewUrlParser: true -)
client.connect(err => -
if (err) return console.log(err)
const db = client.db(-databaseName-)
require('./app/routes')(app, db);
app.listen(port, () => -
console.log(-We are live on - + port);
-);
-)
Where databaseName is however you want your database to be called. This way the -db.collection(...)- call within the routes files will work.

reply

Thanks man great tutorial, just an FYI in the year 2020 after MongoDb version 3 was released the database connection doesn't return a database object it returns a client object and as a sub-object to the client object you can access the database object so now if you want to indicate a collection it's client.db('notes').
reply

thank you for the tutorial, mLab is no longer accepting new customers and redirects to mongoDb Atlas. could you tell how to proceed to create the db since I could not find the same menus on this new platform?otherwise, is it possible to create the db through the terminal? thank you very much for your answer
reply

if i use latest version of mongoose (v5 ?) in dependencies and latest driver 3.0 above, rest of the codes the same. Will it still work?? (currently using 2.2.33, driver 2.2.12 or later....)
reply

As of February 2019, mLab does not allow you to create a new account and log in to that account. Instead, you have to use MongoDB Atlas. How can I get my URL from there?
reply

PostMan chrome extension is now deprecated but the desktop app is working well. Same stuff for Mlab which is now MongoDB =).
Thanks for this tutorial !

reply

Thank you, it was so helpful to build my first api as a non-developer ! With mongoDB cloud atlas and. the trick db.db('database').collection
reply

Are there any rules to set the post number? I've changed 8000 to 3000 and sent the data from Postman, then the Node prompet didn't response.
reply

Typos everywhere ! :'/
I can't focus on what you say because I get distracted by every typo.
Could have been great otherwise.

reply

I got this from Postman: -
Error
Cannot POST /notes
-
instead of
-hello-

reply
Add a review, comment






Other channel videos