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

271
Views
Form Submit 404 Not Found Error

Hi I am currently learning NodeJS and the Express framework, but I am having issue with when I try to submit the form it suppose to go the '/users/register' URL but it seems that my app.js is not finding the register.jade file although I have a register.jade under the view folder. Here is some of my codes:

register.jade:

extends layout

block content
    h1 Register
    p Please register using the form below
    ul.errors
        if errors
            each error, i in errors
                li.alert.alert-danger #{error.msg}
    form(method='post', action='/users/register', enctype='multipart/form-data') ...

user.js:

router.post('/users/register', function(req, res, next) { ... });

app.js:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var expressValidator = require('express-validator');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var passport = require('passport');
var local = require('passport-local').Strategy;
var bodyParser = require('body-parser');
var multer = require('multer');
var flash = require('connect-flash');
var mongo = require('mongodb');
var mongoose = require('mongoose');
var db = mongoose.connection;

var index = require('./routes/index');
var users = require('./routes/users');

var app = express();

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
...
app.use('/', index);
app.use('/users', users);

app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

Error on my Git Bash:

giterror

Error from the browser:

browsererror

Here is my folder structure:

folderstructure

I am not sure why it errors out 404, thank you in advance!

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The routes in your users router are relative to the mounted path, you should instead try:

router.post('/register', function(req, res, next) { ... });
about 4 years ago · Santiago Trujillo Report

0

As per the path mouting from your code, the url path in browser should be

localhost:3000/users/users/register


Either you can make change in

router.post('/users/register', function(req, res, next) { ... });

to

router.post('/register', function(req, res, next) { ... });

OR only make change in

app.use('/users', users);

to

app.use(users);

where your url path will be localhost:3000/users/register

about 4 years ago · Santiago Trujillo 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!