I have a node.js app that loads a signup form when visiting localhost/user/signup:
html
head
script(type='text/javascript',src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js')
script(type='text/javascript',src='javascripts/validator.js')
script(type='text/javascript',src='javascripts/signupValidation.js')
body
p(id='error', style='display:none;')#{error}
form(id='signup',method='post',action='/signup')
label(for='firstname') Firstname
input(type='text', name='firstname')
label(for='lastname') Lastname
input(type='text', name='lastname')
label Username
input(type='text', name='username')
label Password
input(type='password', name='password')
label Password again
input(type='password', name='password2')
label Email
input(type='email', name='email')
input(type='submit',value='Sign up', onclick="")
but when I access the page the server console logs a 404 error getting the JavaScript files, it was working fine until only resonantly when I changed the signup page to be loaded from localhost/signup
to localhost/user/signup
:
app.get('/signup',user.signupForm);
to:
app.get('/user/signup',user.signupForm);
From you question I assume, that you did not move the JavaScript files along, so your directory structure looks like this:
localhost
|- user
|-- signup
|- javascripts
In that case, the relative paths of you JavaScript files have to be changed in order to point towards the correct files:
script(type='text/javascript',src='../javascripts/validator.js')
script(type='text/javascript',src='../javascripts/signupValidation.js')
Remember that if you don't use absolute paths, paths are always treated as relative to the current directory, so in your case the system is searching for the JavaScript files in localhost/user/javascripts/
, which does not exist and thus results in the 404 errors!