Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,194,163 members, 7,953,623 topics. Date: Thursday, 19 September 2024 at 08:58 PM

Someone Kind Enough Should Help Me With My Node.js Use.app() Path - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Someone Kind Enough Should Help Me With My Node.js Use.app() Path (572 Views)

Free PHP, Node js ,Mongo db, Angular And C# Proje Source Code With Documentation / React + Node Js : Fullstack Web Development Training / Please Help Me Test Out My Node JS Script (2) (3) (4)

(1) (Reply) (Go Down)

Someone Kind Enough Should Help Me With My Node.js Use.app() Path by Princedapace(m): 5:09pm On Sep 07, 2021
So, I am trying to create a comment in my blog applictaion. I am using node.js.

Here is my comment route path:

router.post("/posts/:id/comment", async (req, res) =>{
const newComment = new Comment(req.body);//we create a new category for the database

try{
const savedComment = await newComment.save();//we need to try and catch the new category and save it
res.status(200).json(savedComment)
}catch(err){
res.status(500).json(err)
}
})

The idea is to create comment inside a post.

Here is the server path for the comment:

app.use("/api/posts/", commentRoute)

I think here is where I am missing it. Someone can direct me, pls.
Re: Someone Kind Enough Should Help Me With My Node.js Use.app() Path by ClintonNzedimma(m): 6:26pm On Sep 07, 2021
Princedapace:
So, I am trying to create a comment in my blog applictaion. I am using node.js.

Here is my comment route path:

router.post("/posts/:id/comment", async (req, res) =>{
const newComment = new Comment(req.body);//we create a new category for the database

try{
const savedComment = await newComment.save();//we need to try and catch the new category and save it
res.status(200).json(savedComment)
}catch(err){
res.status(500).json(err)
}
})

The idea is to create comment inside a post.

Here is the server path for the comment:

app.use("/api/posts/", commentRoute)

I think here is where I am missing it. Someone can direct me, pls.
Push to GitHub for a better explanation.
I think I can help you

1 Like

Re: Someone Kind Enough Should Help Me With My Node.js Use.app() Path by Heathen(m): 7:52pm On Sep 07, 2021
What's the actual problem? Your post doesn't state the actual problem
Re: Someone Kind Enough Should Help Me With My Node.js Use.app() Path by spartan117(m): 7:20am On Sep 08, 2021
I'm guessing you exported the router from that file. If you did then the issue I can see here is that you repeated "posts" in both the router path and the app path. So your final path looks like this:
/api/posts/posts/:id/comments.

Posting the full code will help though because I'm not even sure if you are using express app and express router correctly. But this is all I can see that is wrong from what you posted.
Re: Someone Kind Enough Should Help Me With My Node.js Use.app() Path by Princedapace(m): 6:38pm On Sep 08, 2021
spartan117:
I'm guessing you exported the router from that file. If you did then the issue I can see here is that you repeated "posts" in both the router path and the app path. So your final path looks like this:
/api/posts/posts/:id/comments.

Posting the full code will help though because I'm not even sure if you are using express app and express router correctly. But this is all I can see that is wrong from what you posted.
i have sorted out the problem. Thank you bro
Re: Someone Kind Enough Should Help Me With My Node.js Use.app() Path by Princedapace(m): 6:59pm On Sep 08, 2021
ClintonNzedimma:

Push to GitHub for a better explanation.
I think I can help you
I have sorted out the problem, bro. Thanks

just have another problem with mongodb


My postman is throwing this error when I want to add second comment. Thefirst comment goes on well. When I now want to add another, I get this error.

{
"driver": true,
"name": "MongoError",
"index": 0,
"code": 11000,
"keyPattern": {
"title": 1
},
"keyValue": {
"title": null
}
}

(1) (Reply)

Laravel Vuejs Chat App / I Made This Yoruba Animal Names App / Help Me In Making The Right Choice ,HP Elite 8440E WINDOW 7 I5 Vpro,55k

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.