Ah...that makes sense. I moved the code inside the callback and it does indeed work. That was sort of in the back of my mind, but I think I got thrown by the fact that the web process worked fine, so I assumed this script should also be fine.
Thanks for the help Warren! On Tuesday, September 30, 2014 4:50:18 AM UTC-7, Warren Lindsey wrote: > > Hi Guy, > > Connect is an async call, so it returns immediately, even if you're not > connected yet. Calls to the db care queued up until the connection is > established. > > What is probably happening is the node script runs through the connect and > get and then exits right out the end before waiting for a response. The > webserver works because its a long running process and there is time for > that setup code to work. > > Move your get code into the connect callback or wrap them with the > waterfall function from the async package. > > Cheers, > Warren > > > On Sep 29, 2014, at 11:47 PM, Guy Knights <guy.k...@gmail.com > <javascript:>> wrote: > > I'm writing an application in nodejs and am using the couchbase nodejs > library, version 1.2.4. My web application works fine and connects to > couchbase without any problems - I can get and set documents without any > issues. > > However, I'm writing a maintenance script to be run from the command line > (Linux) and for some reason I can't deduce, it fails to connect to > Couchbase at all. I'm using exactly the same connection code for this > command line script as for my web application, which is the following: > > var cb = new couchbase.Connection({ > host: config.couchbase.host, > bucket: config.couchbase.bucket, > username: config.couchbase.username, > password: config.couchbase.password > }, function(err) { > if (err) { > console.log(err); > process.exit(1); > } > }); > > I follow the above with a standard get operation but it was returning > nothing, so I started debugging further, and discovered that the contents > of the cb object after executing the above connection code is: > > { queryhosts: null, > mchosts: '', > srvhost: null, > hosts: '127.0.0.1:8091', > _cb: { _handleRestResponse: [Function] }, > connected: false } > > The other thing is that even the callback function which should log to > console any connection errors outputs nothing at all. I even put a log > statement outside the IF and that didn't get executed at all. It just seems > like it doesn't even try to connect. > > Does anyone know what might be going on here? It's driving me batty and I > can't understand why it won't work. The maintenance script is running from > the same dev server which hosts both the application and the couchbase > server, it's using the same config file with the same connection > parameters, and as I said, it's the same connection code. > > Thanks, > Guy > > -- > You received this message because you are subscribed to the Google Groups > "Couchbase" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to couchbase+...@googlegroups.com <javascript:>. > For more options, visit https://groups.google.com/d/optout. > > -- You received this message because you are subscribed to the Google Groups "Couchbase" group. To unsubscribe from this group and stop receiving emails from it, send an email to couchbase+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.