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

141
Views
Simple NodeJS Express App Cannot get /url

I've been at this for about an hour now and I have no idea what's wrong here. I can't access the url. I made this Simple NodeJs Express app but when I access http://localhost:3000/users/login It gives an error Cannot GET /users/login

This is my app.js File.

const express = require('express');
const indexRouter = require('./routes/index');
const userRouter = require('./routes/users');
const app = express();
const port = process.env.PORT || 3000;


app.set('views', 'views');
app.set('view engine', 'ejs');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));


app.get('/', indexRouter);
app.get('/users', userRouter);

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

This is my routes/index.js file

const express = require('express');
const router = express.Router();

router.get('/', (req, res) => {
    res.send("Welcome");
})

module.exports = router;

This is my routes/users.js file

const express = require('express');
const router = express.Router();

// Login Route
router.get('/login', (req, res) => {
    res.send("Login page");
})
// Register Route
router.get('/register', (req, res) => {
    res.send('Register Page');
})

module.exports = router;

Can anyone please tell me what's the issue here?

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

0

Maybe instead of app.get('/users', userRouter) try app.use('/users', userRouter)

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!