0

Im training right now in nodejs and how to develop MVC applications using nodejs and expressjs as a framework. I have a TDD approach along with the Model and View classes written along with TDD test scripts. I have a mongodb test script and it fails with the the following error message:

expressjs_multech_project mul$ jasmine-node ./tests
.......F

Failures:

  1) MongoDB is there a server running?
   Message:
     Expected {  } to be null.
   Stacktrace:
     Error: Expected {  } to be null.
    at /Users/.../expressjs_multech_project/tests/mongodb.spec.js:6:19
    at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/mongo_client.js:334:20
    at /Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/db.js:258:16
    at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/server.js:621:7)
    at emitThree (events.js:110:13)
    at emit (events.js:188:7)
    at null.<anonymous> (/Users/.../expressjs_multech_project/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:139:15)
    at emitTwo (events.js:100:13)

Finished in 0.182 seconds
8 tests, 18 assertions, 1 failure, 0 skipped

Im using Jasmine for node as a test package and all other tests pass with just the model and view classes written. I don't understand why my mongodb TDD script fails on mongodb and when I npm start, it does not start returning the app.js error message of:

> node app.js

Sorry, the server (mongodb) is not running

I researched back the stack trace and from what I can see, there is no connection been made with mongodb and its returning null. I checked mongodb to make sure its there:

Johns-MacBook-Pro:expressjs_multech_project mul$ npm list mongodb
multechanalytics@0.0.1 /Users/.../expressjs_multech_project
└── mongodb@1.3.10 

I have tried allot of remedies but nothing to date is working. Any ideas on resolving the connection issue with the server so I can proceed with this expressjs MVC training project?

my config/index.js looks like this:

var config = {
    local: {
      mode: 'local',
      port: 3000,
      mongo: {
        host: '127.0.0.1',
        port: 27017
      }
    },
    staging: {
      mode: 'staging',
      port: 4000,
      mongo: {
        host: '127.0.0.1',
        port: 27017
      }
    },
    production: {
      mode: 'production',
      port: 5000,
      mongo: {
        host: '127.0.0.1',
        port: 27017
      }
    }
}
module.exports = function(mode) {
  //export module configuration making it available to all files in folder
  return config[mode || process.argv[2] || 'local'] || config.local;

Here is the ouputs I got when I augmented the package.json file and npm install mongodb --save to run the install mongo after npm install

muls-MacBook-Pro:expressjs_multech_project jmulhall$ npm install mongodb --save

> kerberos@0.0.11 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/kerberos/lib/kerberos.o

> bson@0.2.22 install /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)

  CXX(target) Release/obj.target/bson/ext/bson.o
multechanalytics@0.0.1 /Users/jmulhall/Documents/Web_Development/Express-Nodejs/expressjs_multech_project
├─┬ less-middleware@0.1.12
│ └─┬ less@1.4.2
│   └─┬ request@2.69.0
│     └─┬ bl@1.0.3
│       └─┬ readable-stream@2.0.6 
│         └── isarray@1.0.0 
└─┬ mongodb@1.4.40 
  ├─┬ bson@0.2.22 
  │ └── nan@1.8.4 
  ├── kerberos@0.0.11 
  └─┬ readable-stream@2.0.6 
    └── isarray@1.0.0 

Thanks...

John Mulhall
  • 173
  • 3
  • 12
  • Hi John It's not clear from the info if you have validated that your mongo server is up. Are you running mongodb locally or from a service provider? – Number 9 Mar 21 '16 at 17:03
  • Hi 9, its running locally at 127.0.0.1:27017 – John Mulhall Mar 21 '16 at 17:14
  • 9, I have ran npm start and its failed to launch, that is the basis of my validation of mongdb server validation. – John Mulhall Mar 21 '16 at 17:16
  • Ok but the node library doesn't think mongo is up and running. When you run 'mongo' the command line client installed with mongodb what do you get? – Number 9 Mar 21 '16 at 17:20
  • 9, I get nothing... nothing for mongd, mongodb or any other iteration you can think of with "mongo" in it – John Mulhall Mar 21 '16 at 17:21
  • I thought I had fixed this but obviously I was wrong.. any tips on checking for a running server and fixing it? – John Mulhall Mar 21 '16 at 17:22
  • You can check it as per this post here http://stackoverflow.com/questions/5091624/is-mongodb-running `ps -edaf | grep mongo # "ps" flags may differ on your OS` As for fixing it that depends on whether its due to environment config or a bad install – Number 9 Mar 21 '16 at 17:25
  • 9, thank you.. here is the CLI output from inputting your command as above: 501 21061 15192 0 5:34pm ttys000 0:00.01 grep mongo. Any ideas on this? Ill post my config.js above right now... – John Mulhall Mar 21 '16 at 17:35
  • ok that looks like mongo is not running as the only response is for the `grep` what instructions have you followed for installing mongodb? https://docs.mongodb.org/manual/installation/ – Number 9 Mar 21 '16 at 17:55
  • 9, thanks for the confirm, I have node and npm installed so I I set up by package.json with it configured for a few packages including mongodb and went and typed "npm install --save" – John Mulhall Mar 21 '16 at 18:14
  • 9, you were right, Ill post above the error messages in the reinstall of mongodb... – John Mulhall Mar 21 '16 at 18:30

1 Answers1

1

That doesn't look like an error from install as the components return exit 0 which is fine.

To be clear though the package you are installing is only the official mongodb driver https://www.npmjs.com/package/mongodb - The official MongoDB driver for Node.js. Provides a high-level API on top of mongodb-core that is meant for end users.

You need to install the mongodb server to have a full install https://docs.mongodb.org/manual/installation/

Number 9
  • 615
  • 3
  • 9
  • Great stuff Number 9... I got it fixed.. but not after learning loads about mongodb and its installation. Im a brew fan but this time round the extras on brew seem to be causing more bad installs. – John Mulhall Mar 22 '16 at 16:50
  • I found a very clear installation blog article and followed it and its now working on my local machine (Mac OSX 10.11.4). I also ran the TDD tests again on my MVC app and its passed all tests including the mongodb test script I checked about a thousand times yesterday! The link to the blog/tutorial for manual installs is http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/ ... I would say that I find nano easier then vim so I used nano to update my bash_profile. The manual installation worked a charm. Thank you sir for all your help and inputs... you are a king amongst men!!... – John Mulhall Mar 22 '16 at 16:50