1.1 MEAN Stack
MEAN is an acronym for MongoDB, ExpressJS, AngularJS and NodeJS.
MEAN is a technology stack for building frontend and backend apps served by Express.js with data persistance provided by MongoDB.
This set of build notes is based on the the course: MEAN Stack and MongoDB Development Techniques
Setting up the app requires a fair bit of installation to support the front the front end and the back end.
1.2 Install Node
1.2.1 From Nodejs.org
Go to Nodejs.org and download node.js
Install Node.js using the installer
NPM is installed with Node
Verify the installation
node -v
1.2.2 Using Homebrew
Using homebrew is probably the best way to install node.js. It makes updating and version control easier.
Follow the instructions at Homebrew.
1.3 Install MongoDB
Go to MongoDB follow the instructions to install manually or, install with Homebrew, which is my prefered method.
Check your Homebrew installation
brew doctor
Update Homebrew
brew update
To install the MongoDB binaries that have TLS/SSL support:
brew install mongodb --with-openssl
1.4 Setup Mongo Data Folder
Before starting MongoDB create the folder in which you want to store data.
sudo mkdir -p /data/db
Check permissions are granted on the data directory.
ls -ld /data/db/
1.4.1 chmod
sudo chmod 0755 /data/db
1.4.2 chown
If you know the id of your mongod
for example
mongod:x:498:496:mongod:/var/lib/mongo:/bin/false
You can Chown
sudo chown -R 498:496 /data/db # using the user-id , group-id
Or try:
sudo chown -R `id -u` /data/db
or,
sudo chown -R $USER /data/db
For more info on setting permissions on the mongo data folder: stackoverflow
1.5 Launch MongoDB
Once you have installed mongodb and set up data folder, and checked permissions, you can launch MongoDB.
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
or,
mongod
1.5.1 Issues on startup
On running MongoDB you may get a warning:
** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
With most UNIX based OS's system resources such as network connections, files and threads are limited and controlled on a per-process and per-user basis. Known as "ulimits" these controls and limitations prevent excessive consumption of system resources by a single user.
Generally, for development purposes, if these limits are low they won't cause any problems with the functioning and usage of MongoDB. The exception to this would be if you needed to work with a large number of files or connections.
That said it's a good idea to resolve those low limits as it helps ready your database for any potential increase in requirements (say for a new project with larger datasets).
You can fix this by running
ulimit -n 2048 && mongod
1.6 Check your progress
If you run
mongod
you should see the mongo server waiting for connections on port: 27017
In a new terminal window, if you run:
mongo
You should see mongo connect to test db and back in the mongo server window you should see a connection has been made.