title: AngularJS and ExpressJS session management?
body: <p>I would like to keep session across all the page.  For this project, I am using expressJs, nodeJS as server side. AngularJS in front end. </p>
  
  <p>I am not sure, how to handle session when view changes or url changes. Because I need to take care of both <strong>expressJS router or angularJs router</strong>.  </p>
  
  <p>What approach should I follow?</p>
  
  <p><strong>angularJS router</strong></p>
  
  <pre><code>     myApp.config(['$routeProvider', function($routeProvider) {
  
      $routeProvider.when('/welcome', {templateUrl: 'partials/welcome.html', controller: 'MyCtrl2'});
      $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'MyCtrl2'});
      $routeProvider.when('/signup', {templateUrl: 'partials/signup.html', controller: 'singupController'});
      $routeProvider.otherwise({redirectTo: '/'});
    }]);
  </code></pre>
  
  <p><strong>Signup controller</strong></p>
  
  <pre><code>myApp.controller('singupController',function($scope,$rootScope,$http){
  
      $scope.doSingnup = function() {
  
         var formData = {
            'username' : this.username,
            'password' : this.password,
             'email' : null
        };
  
        var jdata = JSON.stringify(formData);
  
        $http({method:'POST',url:'/signup',data:jdata})
        .success(function(data,status,headers,config){
  
                  console.log(data);
  
        }).
        error(function(data,status,headers,config){
  
          console.log(data)
  
        });
      }
    })
  </code></pre>
  
  <p><strong>ExpressJS router</strong></p>
  
  <pre><code>    module.exports = exports = function(app, db) {
  
      var sessionHandler = new SessionHandler(db);
      var contentHandler = new ContentHandler(db);
  
      // Middleware to see if a user is logged in
      app.use(sessionHandler.isLoggedInMiddleware);
  
      app.get('/', contentHandler.displayMainPage);
  
      app.post('/login', sessionHandler.handleLoginRequest);
  
      app.get('/logout', sessionHandler.displayLogoutPage);
  
      app.get("/welcome", sessionHandler.displayWelcomePage);
  
      app.post('/signup', sessionHandler.handleSignup);
  
      app.get('*', contentHandler.displayMainPage);
  
      // Error handling middleware
      app.use(ErrorHandler);
  }
  </code></pre>
  
  <p>After signup, I would like to redirect to the login page. How can I do that in the above router. which one of the following  should I use to change the view of app<br>
            1) $location of angularJS<br>
            2) redirect of ExpressJS  </p>