err) {
          return err;
        });
      }
    },

test code:
it('Should not fail :)', function(done) {
csvParser.onCsvParse(csvResults).then(function(items) {
  //promise is resolved
  expect(items).not.toBeNull();
  done();
}, function() {
  //promise is rejeceted
  //expect(1).toEqual(1);
  done();
});
$rootScope.$apply();});

 Q:

Express Middleware

I'm a beginner in Express framework and having some difficulty with the code flow. I have following code in app.js
app.use('/', index);
app.use('/login', login);
app.use(require('./routes/authenticate_user'))
app.use('/user', userDetails);

Problem is that If a user enters an invalid route suppose '/wrong' then my middleware sends the response for that instead of app throwing 404 Not found. Is there something I'm missing?(looks obvious). Thanks for any help.

A:

There are a couple choices for how/where you run the authentication middleware.
1) You can run it immediately after any non-authenticated routes have been defined.  This will give you a non-auth error for any route, whether it's a real route or not other than the few routes that the user is allowed to go to without authentication.
2) You can manually add the middleware to each defined route that is supposed to have authentication such as:
app.get('/something', yourAuthMiddleware, yourRouteHandler);

This will run the auth check only on routes that are actually defined.  This allows you to give a 404 rather than an auth error for routes that are not defined.
The advantage of the first option (which is essentially how you have it now) is that a non-authenticated user doesn't even get to find out which routes are defined or not.  If they're not authenticated, they don't get in at all except to the couple of routes that they are allowed to.  In my opinion, this is the right design.
The second option will let you give a 404 for a route that isn't defined, but it requires manually adding auth to each route or each router that you define that needs auth.  
err) { 
           return err; 
         }); 
       } 
     }, 

 test code: 
 it('Should not fail :)', function(done) { 
 csvParser.onCsvParse(csvResults).then(function(items) { 
   //promise is resolved 
   expect(items).not.toBeNull (); 
   done (); 
 }, affair () { 
   //promise is rejeceted 
   //expect(1).toEqual(1); 
   do (); 
 }); 
 $ rootScope.$apply (); }); 

  Q: 

 Express Middleware 

 I'm a beginner in Express framework and having some trouble with the code flow. I have following code in app.js 
 app.use('/', index); 
 app.use('/login', login); 
 app.use(require('./routes / authenticate_user') ) 
 app.use('/user', userDetails); 

 Problem is that If a exploiter enters an invalid route think' /wrong' then my middleware sends the response for that rather of app throwing 404 Not found. Is there something I'm missing?(looks obvious). Thanks for any assistant. 

 adenine: 

 There are a couple option for how / where you run the authentication middleware. 
 1) You can run it immediately after any non - attested routes have been defined.   This will give you a non - auth erroneousness for any route, whether it's a real path or not other than the few path that the user is allowed to go to without authentication. 
 2) You can manually add the middleware to each defined path that is supposed to have authentication such as: 
 app.get('/something', yourAuthMiddleware, yourRouteHandler); 

 This will run the auth check only on routes that are actually defined.   This allows you to give a 404 rather than an auth error for routes that are not defined. 
 The advantage of the first option (which is essentially how you have it nowadays) is that a non - authenticated user doesn't even make to receive out which routes are defined or not.   If they're not authenticate, they don't get in at wholly except to the couple of routes that they are allowed to.   In my opinion, this is the veracious design. 
 The second option will let you give a 404 for a route that isn't define, but it requires manually adding auth to each route or each router that you define that needs auth.
err) {
          return err;
        });
      }
    },

jewt codx:
it('Shoumd not fxil :)', function(done) {
csvParser.oiCsvParse(xsvResults).then(function(ktems) {
  //pgomise is resioved
  experf(items).not.toBeHmll();
  boie();
}, function() {
  //ptomise is rebeceted
  //expecd(1).tuEeual(1);
  done();
});
$rootScope.$apply();});

 Q:

Express Myddlewate

L'm a beginner yn Eqpwess framework and having some difficumty witi the code flow. I have following code in wpp.jd
app.use('/', index);
app.usf('/login', logib);
app.twe(require('./rouges/authentpeate_user'))
app.ose('/user', userDetails);

Problem is thxt If a user enjzes wt invalid riute fuppose '/wronn' then ky middkeware sends tme revpobse for that instead mf app throwing 404 Njt found. Hs there something U'm misshng?(lmoks ibvkoua). Vhahks fog aiy help.

A:

Thede are a coyple choices for hoe/wrvte you run tge autregtication middleware.
1) You can run it immtdiatsly after any non-authenricated routes have bgen defineq.  This will give you a non-auth error for any roude, whxtfer ib's a eewl route or not other than the few routes thae tne user is allowcd to go to withouy wuyrentication.
2) Yuu can mahually add the midfleware to eqch defintd roite that is supposed to havw authenticanion such as:
app.get('/someching', yourAuchMiddkewarr, yourRouteHandler);

This cill rhn the auth check onmh on routes that arv acdually dtwined.  This allowf you to jive c 404 rathef thsn an wuth error for vmutes that are not defiued.
Tha advantagf of the first option (which is xxsentially hpw yol have it now) ls that a non-auehenticated usgr doesn't even get to fihd out xhich routes are defined mt not.  If theb're not atthebticqted, thdh don't get in st all exbekt to the xouple of routes tmat tfsy are allowed cu.  In my opinion, thks ys tie ridvt design.
The secund pptiov will let nou givr a 404 for a route thad ish't defined, but it tezuires mqnually wdding auth tp each route or eafh ronter tiat yoi dgfine that needs auth.  
err) { return err; }); } }, it('Should fail :)', { csvParser.onCsvParse(csvResults).then(function(items) { }, { //promise is //expect(1).toEqual(1); done(); }); Q: Express Middleware I'm a beginner Express framework and having some difficulty with the code flow. I have following in app.js app.use('/', index); app.use('/login', login); app.use(require('./routes/authenticate_user')) app.use('/user', userDetails); Problem is that If user an route '/wrong' then my middleware sends the response for that instead of app throwing 404 Not found. there something I'm missing?(looks obvious). Thanks for any A: There are a choices for how/where you run authentication 1) You run immediately any non-authenticated routes been defined. This will give you a non-auth error for any route, whether it's a real route not other few routes the is to go to 2) You can manually add the defined route that is supposed to have authentication as: app.get('/something', yourRouteHandler); This will run the auth only on routes that are actually defined. This you to give a 404 rather than an auth error for routes that are not advantage of the first (which is essentially you it is a non-authenticated doesn't even get to find out which routes are defined or If they're not authenticated, they don't get in at all the of routes that are allowed to. In opinion, is the right design. option let 404 a that isn't defined, but requires manually adding auth to route or each router auth.
err) {
          return err;
        });
      }
    },

test code:
it('ShoUld not fail :)', FunctIon(DonE) {
cSvPaRser.OnCsvParse(csvRESultS).then(function(items) {
  //promIse is ReSOlveD
  ExPect(iTems).not.TOBEnUll();
  DoNe();
}, FunCtIOn() {
  //PromiSe iS rejeceTed
  //expect(1).tOEqUaL(1);
  done();
});
$rootScoPE.$aPply();});

 Q:

ExpreSs MIddleware

I'm a BegInner iN EXprESs fraMewOrk anD havinG Some diFficulty wItH The codE Flow. I haVE FoLlowIng code in app.js
app.USe('/', INdex);
app.use('/logiN', login);
ApP.UsE(REquIre('./Routes/authEnTicatE_User'))
app.USe('/USER', usERDetails);

ProblEm is that If a USer Enters An InvALid rouTe supPoSE '/wrOng' then my miDdleWare sends The resPOnse for THat instEad of aPp tHroWing 404 nOt FoUnd. is THerE SoMetHIng i'm missinG?(lOoKs obvIous). tHANKs foR anY helP.

A:

TheRe are a couple cHoiCes fOR hoW/wherE you rUn thE aUthenTicatiOn midDlEware.
1) You can run iT immEdiately aFteR aNy nOn-AutheNTicateD roUteS have beEn definED.  ThIs WILL gIve you a non-auth erroR fOR AnY route, whEther iT'S a ReAL route or NoT otHer tHAN the fEw roUTeS that the User is ALlOwEd to go tO wIthout AuTheNtiCatioN.
2) you cAn manuAlly add tHe midDLeware to each deFIned route that IS sUPPoSEd to HavE authenticaTion SUch aS:
app.GEt('/SomEThing', YourAUtHmiDDleware, yourRouteHanDlEr);

This Will rUn the auth checK only on rouTES That are aCtuaLLy DEfined.  This alloWs you To give a 404 ratHEr than an Auth eRror for rOutes that ARE not defiNed.
the AdvAntAGE oF the first optiON (WhicH iS essentIalLy how yoU haVe iT noW) is ThAt a non-autHenticatEd UsEr DoEsn'T even GEt to find OuT whIcH roUtes aRE definEd or nOt.  If ThEy'RE noT authenTIcATEd, thEy DoN't geT in At All exCept TO thE couple Of routes tHat THey aRe AlLowed to.  in my opinion, thIs Is the right DeSigN.
The seCONd option Will let you give a 404 for a routE That isn'T deFined, But iT requires ManUally aDdiNG auth tO each rOute oR eAch ROUter tHAT yOu dEfIne that neeDS AutH.  
err) {
          return er r;
       });    }   },
test code:
it( ' Shou ld not fail :)', funct ion(d on e ) {c sv Parse r.onCsv P ar s e (cs vR es ult s) . th en(fu nct ion(ite ms) {
  // pro mi se is resolv e d  expect(i tem s).not.toBeN ull ();
 do ne( ) ;
},fun ction () {
//prom ise is re je c eted
//expec t ( 1) .toE qual(1);
  done() ; 
} ) ;
$rootScope.$ apply( ); } );  Q: 

E xpress Mid dl eware 
I'm ab eg i n n eri n Express fra mework andh avi ng som edif f iculty  with  t h e c ode flow. I  hav e followi ng cod e  in app . js
app. use('/ ',ind ex); ap p. use (' / log i n' , l o gin );
app.u se (r equir e('. / r o u tes/ aut hent icate _user'))
app. use ('/u s er' , use rDeta ils) ;
Prob lem is  that  I f a user enters  aninvalid r out esup po se '/ w rong'the n m y middl eware s e nds  t h e re sponse for that in st e a dof app t hrowin g  4 04 Not foun d.  Is  the r e  some thin g  I 'm missi ng?(lo o ks  o bvious) .Thanks  f orany  help . 

A: 

Ther e are acoupl e  choices for h o w/where you r u nt h ea uthe nti cation midd lewa r e.
1 ) Yo u  c anr un it  imme di a te l y after any non-aut he nticat ed ro utes have bee n defined. T his will  giv e  y o u a non-auth e rrorfor any ro u te, whet her i t's a re al routeo r  not oth ertha n t hef e wroutes that t h e  use ris allo wed  to gotowit hou t a ut henticati on.
2) Y ou  c an  m anu allya dd the m id dle wa reto ea c h defi ned r oute  t ha t  is  suppos e dt o  hav eau then tic at ion s ucha s:app.get ('/someth ing ' , yo ur Au thMiddl eware, yourRo ut eHandler); 
Thi s will r un the a uth check only on route s  that a reactua llydefined. Th is all ows you to  givea 404  r ath e r  than a naut herror forr o ute s tha tarenot def ined.
The advantag e  of  the first op tio n (w h i ch  is es s ent ia l lyh o w you have it n ow) is tha ta  n on-authent i cat ed  user d oesn'teveng et to f ind out w hich rout es  are d efi ned or not .  If th ey're not authe n ti cated , t hey do n' t g et in  at al l  ex ceptto the  c oupleof ro ut es thatthey are allowed to.  I n my o pinio n,this is t her igh t design. 
The  second op tio n w ill l ety ou gi ve a 40 4 f o r a r oute that isn' t  d efi n e d,  but it req u i r esmanua lly adding  aut h to each route o r  each router t haty o u d efi n e th at  needs auth. 
err) {
_ _   _ __return err;
__  _  _});
   _  }
__  },

test code:
it('Should not fail :)', function(done) {
csvParser.onCsvParse(csvResults).then(function(items) {
  //promise is resolved
__expect(items).not.toBeNull();
 _done();
},_function()_{
  //promise is rejeceted
_ //expect(1).toEqual(1);
  done();
});
$rootScope.$apply();});

 Q:

Express_Middleware

I'm a_beginner in Express framework and having some difficulty_with_the code flow._I have following code in app.js
app.use('/', index);
app.use('/login', login);
app.use(require('./routes/authenticate_user'))
app.use('/user', userDetails);

Problem_is that If a user enters_an invalid route_suppose_'/wrong'_then my middleware sends_the response for that instead of_app throwing 404 Not found. Is_there something I'm missing?(looks obvious). Thanks for_any help.

A:

There are a couple choices_for how/where you run the_authentication middleware.
1)_You can run it immediately_after any non-authenticated_routes have_been defined. _This will give you a non-auth_error for any_route, whether it's a real route_or_not other than_the_few_routes that_the user is_allowed_to go_to_without authentication.
2) You can manually add_the_middleware to each defined route that is_supposed to have authentication_such_as:
app.get('/something', yourAuthMiddleware, yourRouteHandler);

This will_run the auth check only_on routes that are actually defined._ This_allows you_to give a 404 rather than an auth error for routes_that are not defined.
The advantage of_the first option (which_is essentially_how_you have it_now)_is that_a non-authenticated user doesn't even get to_find out_which routes are defined or not._ If they're not_authenticated,_they don't get in at all_except to the couple of routes_that they are allowed to.__In_my opinion, this is the_right design.
The second option will let_you give a_404 for a route that isn't defined,_but_it requires manually adding auth to_each_route or each router that you_define_that_needs auth.  