nativeInstallermean

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.

    $ mkdir installdir/projects
    
  • Create a new Express project:

    $ cd installdir/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 installdir/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://localhost:3000/. To end the application, terminate the running Express process. Learn more about how to access the application.

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');

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.

Last modification September 5, 2018