Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect in node.js

I'm having some issues with redirecting between directories, the problem is I can manage to redirect to another file in different directory. My directory structure looks like this:

-views
  -add_user.jade

-routes
  -index.js

I try to redirect to add_ user.jade from index.js, how would you guys do it

res.redirect('???');

If index.js in the same directory as views, the code below works

-index.js
-views
  -add_user.jade

res.redirect('./add_users');
like image 269
nihulus Avatar asked Sep 09 '25 22:09

nihulus


1 Answers

You want to redirect to the URL (not the view name) that you want the user to go to.

For example, if the route "/user/add" renders the "add_user.jade" view then you want to use

 res.redirect("/user/add");
like image 128
Hector Correa Avatar answered Sep 12 '25 11:09

Hector Correa