Preparing your Windows box for AWS and a MEAN (Node) website: Install MongoDB as a Windows Service
--
I walk through step by step how to get the Node.JS MEAN.JS scaffolded site working on a Windows 10 machine. This section is about installing MongoDB on your local machine.
Go to parent article — Build a robust MEAN website in under an hour for less than $1/day — part 1
Go to previous article —Preparing your Windows box for AWS and a MEAN (Node) website: Install Node 6.3
If you already have MongoDB running on your local box then go to the next article — Preparing your Windows box for AWS and a MEAN (Node) website: Install Ruby, Gems and Sass
Next, let’s install MongoDb so that we can run the app locally before publishing to AWS.
Click download on the top right.
Download and run the Windows installer for Windows Server 64 bit with SSL Support
Click Next on the first screen of the installer.
Click I accept and then Next.
Click Complete
Click Install and then Yes if you are prompted by Windows User Account Control.
Easy. The installer is done.
Great! Now we have all the necessary software installed to see things running locally and publish to the cloud. Let’s take care of some minor configuration needed in MongoDb.
Configure MongoDb as a Windows Service
MongoDB has wonderful documentation. I’ll be following the steps posted here.
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
I’m going to skip down to the section titled: Configure a Windows Service for MongoDB Community Edition
In our bash admin prompt, let’s create some data directories.
cd c:mkdir datacd datamkdir dbmkdir log
Let’s now set the configuration file in mongodb.cfg
Let’s navigate to where we installed MongoDb.
cd "program files"cd mongodbcd servercd 3.2cd bin
(Use the “ls” command to list the contents of the folder if you need to)
To create the configuration file we’ll type vi mongodb.cfg and press enter.
vi mongodb.cfg
Hit the “i” key to start typing. When you’re done typing hit the “ESC” key followed by typing “:wq” and then Enter.
Our file should look like this. It’s very important that the beginning of each line should be started with two spaces and not a tab character. This is called “yaml” format.
systemLog:
destination: file
path: c:\\data\\log\\mongod.log
storage:
dbPath: c:\\data\\db
VI tip: To enter typing mode press “i” and then begin typing. To save the file hit the “ESC” key and then type “:wq” to write the file and then quit. If you ever need to quit the vi text editor without saving, type “:q!”
Now that your configuration file is saved you are good to try running the mongo service.
Let’s run mongod.exe
./mongod.exe
Great. You’re prompted to allow access through the firewall.
Select both check boxes and click Allow access.
Hit CTRL+C to break out of there and go back to the dollar sign and blinking cursor.
This means that the install works. If you didn’t have to use CTRL+C to exit back to Git Bash, then that means you may have something wrong that caused the service to exit. Double check that your c:\data\db and c:\data\log directories exist and that you have run bash with administrator permissions. (Right click the bash program on the bottom bar, then right click “Git Bash” and select “Run as administrator”)
Now you should be back to our friend the blinking cursor, the prompt.
Type this mongod -config command to install the windows service.
./mongod.exe --config "c:\program files\mongodb\server\3.2\bin\mongodb.cfg" --install
If you’ve received the below error, perhaps you’ve entered a wrong value like me in your mongodb.cfg file
Error parsing YAML config file: yaml-cpp: error at line 2, column 13: illegal map valuetry ‘C:\program files\mongodb\server\3.2\bin\mongod.exe — help’ for more information
Double check that you are indenting your lines with two spaces instead of any tab characters.
Next I start the mongodb service with this net start mongodb command
net start mongodb
Mongodb is good to go.
(Keep in mind that Mongodb allows anonymous access by default. You must secure this either through IAM and security group policies in AWS or by disabling anonymous authentication.)
Go to parent article — Build a robust MEAN website in under an hour for less than $1/day — part 1
Go to previous article — Preparing your Windows box for AWS and a MEAN (Node) website: Install Node 6.3
Go to the next article — Preparing your Windows box for AWS and a MEAN (Node) website: Install Ruby, Gems and Sass