Installing mongodb besides nodejs

Installing mongodb for your local Nelderson Onnline rpg Node server as a services on a windows rig.

Green are the copy and paste stuff, red is the stuff you need to change.

Open command promt and typ:  npm install mongodb –save

Tip from Squareware:  make a .bat file in your node js server folder (the folder with the. Server.js inside of it.) And write down: cmd this way you have the right path for installing modules on your node server.

Head over to Hover over “products” and click “MongoDB Server” – this will take you to the Community Server download page. It will auto-detect your OS and selects the latest official mongodb release to give you the appropriate download link.

When the download is going and before installing read the following notes:
Install mongodb not yet a service if you want to enhance the config file.  As a service will keep mongodb running with less concern. Also make sure to install compass (this is a gui for the database) pretty handy to see what is written inside the database and to alter it’s content.  Altough getting compass installed with this installer didn’t work on my end straight away.
So I just installed it without it and installed compass as stand alone (go to products and click compass) make sure to select the community version.
There are also 3d party mongodb gui viewers, I’m not covering them here.

If your database is working, you can open the mongo.exe from the command line or check in your browser:

From the mongo.exe (command line) you should create a super user that has acces to all database. typ in: use admin

Then typ in, remember this because it can be needed later:
db.createUser({user:”SQW_ROOT“,pwd:”SQUAREWARE_PWD“, roles:[{role:”userAdminAnyDatabase”,db:”admin”}]})

Type in This will create a new empty database for you.
use name.of.database

Typ in and remember your user, pwd, dbname this will be needed later:
db.createUser({user:”SQW_ADMIN“,pwd:”SQUAREWARE_PWD“, roles:[{role:”readWrite”, role: “read”,db:”name.of.database“,}]})

This wil create a user for your database that has only read and write acces, this is enough for the Nelderson online plugin.

Open a new notepad to make sure that you have written down the SQW_admin username, password and you are going to use this in your node js config.

Go the node.js server, open the folder configurations. Open the file config with notepad.
scroll down to the very end where you see the config for your db connection. Overwrite the line with the following  and make sure you save it and restart your node server, with no errors you are good to go.

mongoDBconnect: ‘mongodb://SQW_ADMIN:squareware_pwd@localhost:27017/name.of.database

You notice the port number after locahost is colored orange, this is because you could change that, but you need to continue reading…
If not, your done.

Securing the mongodb a little bit more.

Go to the installation folder of mongdb and open the config file with notepad mongod.cfg.
The first thing you should notice is the default portnumber:
Tip from squareware, always change the default portnumber. Port scanners are mosly starting from 0, so the higher the number you chose the longer it takes that the port scanner sees: “oh, port 65000 is open and running some demon. Make sure you choose a port between: 49152 to 65535. These are caled public / dynamic ports which are not used by standard programs / demons services, like the common internet, rpc, smtp ports.

Make sure to use a bind adress  the standard bind address is that of your loopback adress (locahost / You could change that but I don’t think it’s scenery because if someone broke in your computer they could see the config file already (meaning they got root and then you are screwed anyways, (no hard feelings though)), if you want to have acces from outside make sure you have that IP bind to the list of accepted adressen to connect from.

Altough the port has been changed, it is not necessary to have a landing page and let the wholr world know you are running mongoDB. So best is to add this to the config file for disabling the html landing page:

nohttpinterface = true

Altough you should enable SSL but I don’t think it’s necessary don’t shoot me if it’s going bad… but the data is traveling between your nodejs and the mongodb, which are on the same system… So to leave a lot of frustation I didn’t set this up (yet). But please do if your node and mongo are on different servers / networks, I won’t cover this in this tutorial but feel free to stroll the internet for some manual to set this up.

This is it for the basic security if I left something or forget it, we must add it, because security is important. So if you changed some things at the config file, you need to read on. If notm then not!


If you changes the port number for example, go the node.js server, open the folder configurations. Open the file config with notepad.
scroll down to the very end where you see the config for your db connection. Change the portnumber and make sure you save it.

Example:  mongoDBconnect: ‘mongodb://SQW_ADMIN:squareware_pwd@localhost:64231databasename’

Also make sure you changes the user, password, portnumber and dabasemame to the ones you have created earlier, but you did already..

Tip from Squareware: If you want you could move the database to to the nodejs server map, so you have everything at the same folder (easy for back-up), this is done at the mongodb config file make sure to move the database to the new folder, it’s up to you and don’t forget the change the port number.

Because you may did do some changes on the config file, we need to make sure that mongodb uses it when it starts as a service.
Now open up the .bat file you created earlier at the mongodb server and add the following lines this will run mongo as a servicek, if it doesn’t work it maybe that there are some software changes, best to stroll down the internet for some solutions, but the methods should be the same:


net stop MongoDB
sc.exe delete MongoDB
sc.exe create MongoDB binPath= “\”C:\Program Files\MongoDB\Server\0.1\bin\mongod.exe\” –service –config=\” C:\Program Files\MongoDB\Server\0.1\bin\mongod.cfg\”“ DisplayName= “start_mongo_DB” start= “auto”


Now open up the .bat file you created earlier at the mongo server and add the following line this will start up the server through cmd:
The relative path is pointed to where the database files are located.

mongod –port 27017 –dbpath “C:\program files\MongoDB\Server\2.0\data\db\” –config=\” C:\Program Files\MongoDB\Server\2.0\bin\mongod.cfg\


Restart your whole rig, start the node.js server and see if it’s working with your own mongodb…