The MEAN stack pt.4: getting MEAN

Now, finally, we are ready to get MEAN!

Get Grunt!

npm install -g grunt-cli

Get Git!

sudo apt-get install -y git

GET MEAN!

git clone https://github.com/linnovate/mean.git myproject
#or if you need replica set support:
#git clone https://github.com/pontifier/mean.git myproject
cd myproject
npm install

Configure it!

In config/env/development.json at the top is your DB connection string.

If you have locked down your mongo server or are using replica sets, you will need to make changes here.

The format of the connection string and other options can be found here:
http://docs.mongodb.org/manual/reference/connection-string/

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

You may want to create a database user for your app.

mongo
> use admin
switched to db admin

> db.auth("<admin_username>","<admin_password>")
1

my_replica_set:PRIMARY> use my_app_db
switched to my_app_db

my_replica_set:PRIMARY> db.addUser( { user: "my_app_user",
                                pwd: "my_app_password",
                              roles: [ "readWrite" ] } )

{ the user object }

 

mongodb://my_app_user:my_app_password@host1.domain.tld:27017,host2.domain.tld:27017,host3.domain.tld:27017/my_app_db?replicaSet=my_replica_set

 

Go MEAN!

Grunt

 

You should now be able to connect to your app at port 3000! If you set up a replica set, and 3 node servers, they should all be sharing data through mongo. Try making a user on the first machine, logging in to the second and creating an article, and then looking at the articles you made on the third. They should all be in sync, and you should be able to just shut down the server currently acting as the primary database server without any problems.

It’s Fantastic!

 

 

 

Leave a Reply