awsmean

Create a new MEAN project

If you would like to create a new MEAN project, follow the steps below:

  • Log in to your server console.

  • Create a new folder for your project in the /home/bitnami directory.

    $ cd /home/bitnami
    $ mkdir projects
    
  • Create a new Express project:

    $ cd /home/bitnami/projects
    $ express sample
    
  • The MEAN stack already has the required components installed in Node.js, but if you prefer, you can install them in the new project folder:

    $ cd /home/bitnami/projects/sample
    $ npm install
    
  • Start the application.

    $ ./bin/www
    

This will start the Express server for your application on port 3000.

To access the application and see its output, browse to http://SERVER-IP:3000/. To end the application, terminate the running Express process.

NOTE: Access to the server on port 3000 may be blocked for security reasons. In this case, you must first create an SSH tunnel between your local system and the server before you can access the application using these instructions.

You can now proceed to enhance your project by connecting it with MongoDB or by adding AngularJS.

Connecting to MongoDB

You can connect your application with MongoDB using MongooseJS, an object modelling driver for Node.js. It is already installed in the MEAN stack so you only have to add the following lines to your app.js file:

var Mongoose = require('mongoose');
var db = Mongoose.createConnection('mongodb://USER:PASSWORD@localhost/DATABASE');

On cloud servers, you can also use the MongoDB socket instead of using the TCP/IP connection to MongoDB. Here is an example.

var Mongoose = require('mongoose');
var db = Mongoose.createConnection('mongodb:///opt/bitnami/mongodb/tmp/mongodb-27017.sock/DATABASE');

Note that the socket name depends on the MongoDB port in use.

Refer to this document for information on how to create a database and a database user in MongoDB.

Adding AngularJS

You can use install AngularJS in your application with Bower. Create a file named .bowerrc in your application with the following content:

{ "directory" : "public/javascripts/vendor" }

Then, run this command in the project directory:

$ bower install angular

The necessary files will be copied into the public/javascripts/vendor/angular directory of your application.

Learn more about testing and developing applications with the Bitnami MEAN stack.