generalmean

Create a new MEAN project

To create and run a MEAN application using the Bitnami MEAN stack, follow the steps below.

Create an Express project

  • First, create a new folder to store your Express projects, such as the /opt/bitnami/projects directory, and give write permissions for the current system user:

      $ sudo mkdir /opt/bitnami/projects
      $ sudo chown $USER /opt/bitnami/projects
    
  • Then, to create a new Express application, initialize a new project as below:

      $ cd /opt/bitnami/projects
      $ express --view pug sample
      $ cd sample
      $ npm install
    
  • The Express application can be started by using this command, and it will run on port 3000:

      $ DEBUG=sample:* ./bin/www
    

To access the application, 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. Follow these instructions.

Enable MongoDB for your project

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

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

NOTE: USERNAME, PASSWORD and DATABASE are placeholders for the database username, password and the database name, respectively. Learn How to obtain the MongoDB database credentials and How to create a MongoDB database and user.

Add AngularJS to your project

You can add AngularJS to your application with Bower. Create a file named .bowerrc in your application folder with the following content:

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

Then, run this command in the project directory:

$ bower install angular
Last modification April 24, 2020