javascriptnode.jshttp-redirectwebexpress

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');

Solution

  • 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");