NodeJS Data Access Notes

Drivers for relational DB's


  • MySQL and PostgreSQL


  • Native. Built in C/C++
  • Fast
  • Hard to compile on Windows. Easy to get working on a Mac.
  • Get the node-sqlserver-binary which is a precomiled version of the MsNodeSQL libary when using this on Windows


  • ScriptCS and Node.js interop (to call any .NET code)

Drivers for noSQL Data Stores



  • Check the permissions on the /data/db/ directory:
ls -ld /data/db/

You will see permissions like:

drwxr-xr-x  2 root  wheel  68 May 27 06:40 /data/db
sudo chmod 0755 /data/db
sudo chown mongod:mongod /data/db
  • MongoDB Config file on OSX:usr/local/etc/mongod.conf

Starting MongoDB on OSX

To have launchd start mongodb at login:

ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Then to load mongodb now:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Or, if you don't want/need launchctl, you can just run:

mongod --config /usr/local/etc/mongod.conf

Create first MongoDB User

  • Connect to Mongo: type mongo in the terminal
use admin
      user: "superuser",
      pwd: "12345678",
      roles: [ "root" ]
Create the system user administrator
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
Create a user administrator for a single database.
use records
    user: "recordsUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdmin", db: "records" } ]

Mongo Express

cd /usr/local/lib/node_modules/mongo-express
node app
  • Then you can browse to: http://localhost:8081/
  • The details such as the usernames and passwords are in the config.js


  • Cross Platform MongoDB Management
  • robomong

3T Mongo Chef

  • 3T Mongo Chef is by far the easiest way to manage a Mongo database. It's free for personal use. It works for Mac, Windows, and Linux.