Difference between revisions of "Getting MEAN"

From CSE330 Wiki
Jump to: navigation, search
(Created page with '=== Installation === * To install MEAN, follow instructions [http://mean.io/#!/docs here] on how to get started. * Take a moment and read the rest of the documentations to get f…')
(No difference)

Revision as of 21:54, 29 April 2014


  • To install MEAN, follow instructions here on how to get started.
  • Take a moment and read the rest of the documentations to get familiar with the file structure and idioms.

Running the Default App

  • Init and run an app. Make sure MongoDB is connected and running (if you run into problems, refer to the section on MongoDB)
  • Explore features of the default Article app (such as logging in, adding/deleting articles).

Generating a Package

  • By now you should know what a package is in MEAN. If you don't, read this.
  • Try creating a package named myPackage and locate it inside the packages folder
  • Compare the structure of myPackage folder to that of the default app. Make sure you see both public and server folders and their subfolders.
  • Restart your app, make sure you can see a link to the newly created package.

A Closer Look at the App

Take a look at the directory where you app resides, you will see two folders public and server, which contain code for the client side and server side respectively.


Find article.js in /server/models, read the code, if you have trouble understanding what the code does, review the Mongoose quick start guide.


Define a schema for a model named Phone, name it phone.js and save it in the corresponding folder in 'myPackage' (hint: /packages/myPackage/server/models/) A product needs to have the following fields with specific types. Here is an example of a Phone object can be stored in the MongoDB:

       "age": 0, 
       "id": "motorola-xoom-with-wi-fi", 
       "imageUrl": "img/phones/motorola-xoom-with-wi-fi.0.jpg", 
       "name": "Motorola XOOM\u2122 with Wi-Fi", 
       "snippet": "The Next, Next Generation\r\n\r\nExperience the future with Motorola XOOM with Wi-Fi, the world's first tablet powered by Android 3.0 (Honeycomb)."

This is taken from phones.json used by the AngularJS tutorial. If you have gone through the tutorial, you should have realized that instead of using a DB, json files were used to simplify the tutorial. Find phones.json in /app/phones in the angular tutorial folder and try importing its content to MongoDB so you can use them in your current MEAN package.

Run mongod and connect to mongo shell (mongo --shell), then type "use mean-dev" to switch to database used by mean. Type mongoimport --db mean-dev --collection phones --type json --file <path to phones.json> --jsonArray Type show collections to see if phones are added to your database, type coll = db.phones to see the content of the file.



  • Create a package and locate it. Compare the file structure

Once you init and run an app,