Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Cannot GET while using mongoose

my router.js

const express = require("express")
const Note = require("../models/nodeModel")
const router = express.Router()

router.route("/notes").get((req, res) => {
    Note.find({ show_day: "2020-9-10" })
        .then(foundNotes => res.json(foundNotes))
})

module.exports = router

my server.js

const express = require("express")
const app = express()
const cors = require("cors")
const mongoose = require("mongoose");

app.use(cors())
app.use(express.json())

mongoose.connect("mongodb://localhost:27017/my-app")

app.use("/",require("./routes/noteRouter"))

app.listen(3000,function(){
    console.log("server is running on port 3000");
})

my nodeModel.js

const mongoose = require('mongoose')

const noteSchema = {
    show_day:String,
    diary_day: String,
    content: String
}

const Note = mongoose.model("diary",noteSchema)

module.exports = Note;

When I try to console.log Note.find(), it works. But when I run server.js, browser says Cannot GET/ Why it can't work?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You only have /notes endpoint, there's no / route.

You should change route in router.js like this:

const express = require("express")
const Note = require("../models/nodeModel")
const router = express.Router()

router.route("/").get((req, res) => {
    Note.find({ show_day: "2020-9-10" })
        .then(foundNotes => res.json(foundNotes))
})

module.exports = router

or access /notes instead of /.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!