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

147
Views
My route isnt being founded for some reason

My code is below, I just have a simple setup for now to make sure my routes are working but im encountering a 404 error. I have an app.all thats catching the error but i dont know where the error is happening at.

heres my index.js file where I have my express server setup running the error catching app.all is in this file

const express = require('express')
const cors = require('cors')
const app = express()
const PORT = process.env.PORT || 8000



app.use(cors())
app.use(express.urlencoded({ extended: true }))

const userRoutes = require('./routes/users.js')

app.get('/', (req, res) => {
    res.send('backened is up')
})


app.use('/', userRoutes)

app.all('*', (req, res, ) => res.send('That route does not exist!'))

app.listen(PORT, () => console.log(`Server running on port ${PORT}`))

heres my routes file where im retrieving the data from the users file.

const express = require('express');
const { getUsers, createUser, deleteUser } = require('../controllers/users.js')
const router = express.Router();


router.get('./users', getUsers)
router.post('./user', createUser)

module.exports = router;

and lastly heres my users file inside my controllers file where im setting up data for the client side

const {v4 : uuidv4} = require('uuid')

let users = []

exports.getUsers = (req, res) => {

    try {
        res.send(users)
    } catch (error) {
        console.error(error)
    }
}

exports.createUser = (req, res) => {
    try {
        const user  = req.body

        users.push({...user, id: uuidv4()})

        res.send("User Added Successfully!")
        
    } catch (error) {
        console.error(error)
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change these:

router.get('./users', getUsers)
router.post('./user', createUser)

to this:

router.get('/users', getUsers)
router.post('/user', createUser)

You don't use ./ and ../ in route definitions. Route paths are already relative to whatever the path was when the request was sent to that router.

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!