The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ryanburnett (5) [Avatar] Offline
I'm stuck on "4.1 Logging in with $http" (page 65) in the MEAP version 6. I've also read other forum posts on the topic but can't get this working. Here are my steps:

- npm install -g require
- git clone
- cd ch04/simple-server
- npm install
- node app.js
- Express server listening on port 3000
- Open simple-server/public/index.html
- Edit this:

<script src="//"></script> this:

<script src=""></script>

- Open index.html in Chrome
- I click "Submit" to login but nothing happens:

I'm running:
- OS X 10.9.2
- node v0.10.26
- npm 1.4.3
- git

This repo hasn't been updated in over 11 months, so I'm not sure if this even matches the MEAP anymore. Really losing faith in this book.

Any idea how I can get 4.1 working?

Message was edited by:
dnissley (5) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
I've noted a couple other changes you need to make in order to get a little further:

- Add the ng-cookies module, right after the script tag that includes angular:

<script src=""></script>

- Include the cookies module as a dependency when creating your app module:

angular.module('myApp', ['ngCookies']).
controller('MainCtrl', function($scope, $http, $cookieStore) {

- Even then there seems to be a problem with the simple-server, as it is not responding with a token. The res.token property is undefined, the only property on res is loggedIn.

This makes sense because in the login routes file (routes/login.js) on the function when the response is returned there is no other property defined in the response other than loggedIn. So we can change that like this in the function:

loggedIn: loggedIn,
token: token


- Our troubles don't end there though, because after logging in and then refreshing the page you should still be logged in (because we stored the token). Still investigating here.
dnissley (5) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
Ok, now I know what needs to happen. Looks like the cookieParser middleware was forgotten to be used in the main simple-server app.js, so include it there before the router middleware is included:

(before app.use(app.router)smilie

After that you can access cookies in the login.js route with req.cookies.

So in the login.js script in the exports.get function, we can replace the reference to req.body.token with a reference to req.cookies.sessionToken now and it should work, right?

loggedIn: tokens[req.cookies.sessionToken]

But it still doesn't work! This is because the session token has double quotes around it, so in the line before that you need to strip them:

req.cookies.sessionToken = req.cookies.sessionToken.replace(/"/g, "");

And now finally you will still be logged in. (Although of course, after restarting the simple server all of the tokens will be lost because they are only in memory and you will be considered logged out again, but just log in again and refresh and it should work.)
dnissley (5) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
So even after doing all this, the chapter rapidly devolves into spaghetti and I don't really know where to go from there. Repeated and straight up wrong code, etc. Just a mess that I can't make heads or tails of.

But it is a work in progress so I'll be as patient as I can. Hopefully there will be an update soon!
Lukas Ruebbelke (107) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
The entire chapter is being rewritten from the ground up and I am eliminating the node dependencies entirely. Expect an update within the next week.

Also if you have any specific questions, please hit me up at in the meantime. Thanks!
tombrokeoff (13) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
The chapter update that you speak of, I am using the MEAP version that was updated on May 8th - does this include the Chapter 4 updated? It still seems very confusing to me.
realtebo (45) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
I read this forum because I'm deciding if buy the book

I read that example are base on 1.04 ! Really ?!?!

So the book was old just now.
Please, tell me I'm wrong
Lukas Ruebbelke (107) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
You're wrong smilie I am updating everything to 1.3
realtebo (45) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
Ok, I'll buy
nikolazius (1) [Avatar] Offline
Re: Stuck on "4.1 Logging in with $http" (page 65)
Beginning of the book was very promising, easy to read, easy to test/try, but then ...

Is it still under development or work is stopped at all?
Is there an update schedule?
Book is stated to be in nov"14, and we expected to have nearly finished book through the MEAP, rather than a collection of drafts and snippets (especially chapter#4 is a set of snippets, but not the chapter of the book).

Please, correct me if I'm wrong, but we order books from MEAP and similar early access programs quite often, to be on the edge. And this is the first time we are disappointed. Maybe there is an upcomming huge update? this will explain everything.