The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Seems to hang on instance.save function...

Hello. I'm still trying to get past the very first part of the Jump Start Node.js book where you set up the authentication form and try to connect to the mongodb database. I set up everything exactly according to the book. However when you click the "Sign Up" button it would keep timing out. So then after adding various console.log's throughout the code I was able to determine that it connects to the database just fine so that users credentials I initially set up are just fine. I was also able to determine that it appears to be hanging on the part in the User.js file where it does the instance.save function because I can get a console.log message to fire just before that line but if I put another console.log message right after that line (inside of the callback function), that console.log message does not fire ever. So it's something about that save function that is messing it up.

I'm going through the book while at work during some down time where I'm allowed to further my javascript education so could there be something with how the network where I work is set up that is blocking the save function from working? I just figured that since I can connect to the database just fine I should be able to write to it as well but that doesn't appear to be the case at the moment.

Anyone have any ideas for me? If not I'll just have to wait until I get home and try this all out again from there and see if things work. I've already compared all of my source code (line by line) to the source code I downloaded from the books website and besides all of the console.log statements I've put in, it is identical as far as I can tell. However, just to be safe I think I'll load up the downloaded source and of course change the database connection username and password and what not and see if the downloaded source will go through.

Using the downloaded source didn't make a difference. It still appears to hang right at the instance.save function call. For now I guess I'll just wait until I get home and see what happens there but if anyone has a suggestion I would appreciate it.

Let me know if you're having trouble getting this to work at home, that way we can at least rule out network issues.

I don't really recall having any weird issues like that when using the book. Some other things to check are:
- Can you console.log() inside the instance.save() callback (specifically would be worth seeing if an error is returned in the 'err' variable)
- Does the callback you specify to the addUser function get called at all?

It's worth noting that further on you'll install a local MongoDB instance (Beginning of Chapter 3) - if you continue to have trouble connecting/saving to MongoLab then that might be another way to keep going.

I'm still trying to get this whole thing set up on my Windows system here at home. For some reason when I go to localhost:3000/form I get the message "Cannot GET /form". What the heck does that mean? Anyone know how to set this stuff up on a Windows system?

That might mean you don't have a route set up for /form or that you don't have a "form.html" in place

You can run NodeJS fine on windows, the only part of the book that can be a little troublesome on Windows is running the tests using "make", which is a build tool traditionally installed on *nix systems. However there is a simple way to get around this by running the tests directly using Mocha. (The testing framework used in the book.) (See this post)

Well, I am using the source code downloaded from the books website. So I do have a form.html. Everything is set up like I had it on my Mac at work and I didn't have this problem at work. I don't know how I'm going to finish the book if I can't this running on either machine. Are there any other reasons it wouldn't be able to get /form?

Nevermind. For some weird reason after I put in a console.log command it started working just fine. Also as to my first problem with the instance.save hanging on me while on my Mac at work, well it doesn't hang here at home so it's something with the network setup at work. Kind of sucks but that's the way it goes. At least I can go ahead and go through the rest of the book here at home. Thanks for all the help though AussieJohn, I appreciate it.

Nevermind. For some weird reason after I put in a console.log command it started working just fine. Also as to my first problem with the instance.save hanging on me while on my Mac at work, well it doesn't hang here at home so it's something with the network setup at work. Kind of sucks but that's the way it goes. At least I can go ahead and go through the rest of the book here at home. Thanks for all the help though AussieJohn, I appreciate it.

Glad you got it working

In Chapter 3 the book continues on with a local MongoDB install, so you should be able to pick things up on your work computer again.

Seanmyr, further to AussieJohn's excellent reply I would say that a local install satisfies the vast majority of real world use cases. You're not missing out on much if you never end up using remotely hosted MongoDB. I included that in the first chapter firstly to give a taste of what's possible and secondly to get readers up and running with a simple application as quickly as possible.

Thanks for the info. I am enjoying the book so far. I tried asking a couple of people at work why it would hang on that particular command while on my employers network but not at home and nobody had any answers for me but that's ok. I actually prefer to do these tutorials on my home computer anyway!

It's probably a firewall related issue. At a guess I would say they only allow port 80 traffic whereas MongoLab use ports such as 45243. I'm glad you are enjoying the book feel free to ask more questions if you get stuck or if something is not clear

Hi,
Thank you all, i've just spent 8 hours on the same problem here, same situation with the book and the save thing.
I've looked everywhere but no solution till ... here ... changed my network, hen everything worked just fine.
I've just registered in the forum to tell you thank you all .