We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

How To Use the MEAN One-Click Install Image

UpdatedMarch 30, 2018 74.8k views One-Click Install Apps MEAN MongoDB Node.js DigitalOcean
asb
By:
Andrew SB

MEAN is a quick start boilerplate for creating applications based on MongoDB, Node.js, Express, and AngularJS. DigitalOcean's MEAN One-Click Application pre-installs the Mean.js implementation of the stack. It also comes with the front-end package manager bower and grunt, a tool for automating JavaScript tasks. Together, these tools provide a solid base to build your web application.

Creating the MEAN Droplet

To create a MEAN Droplet, start on the Droplet creation page. In the Choose an image section, click the One-click apps tab and select the MEAN image.
Next, select a size, your desired region, and any additional settings (like private networking, IPv6 support, or backups). Add SSH keys and fill in a hostname for the Droplet. When you're ready, click Create Droplet to spin up the server.

Once you have created the Droplet, connect to it using SSH:

  • ssh root@your.ip.address

When you connect, the message of the day will explain how to get started:

-------------------------------------------------------------------------------
Welcome to the MEAN Stack!

MEAN has been installed via "docker-compose"

- To run the sample application and for development work, run the 
   mean-do.sh script which disables public access to MongoDB:

        /opt/mean/mean-do.sh

  When the script is finished running, visit your site at <IP>:3000

- For production sites start the stack with the following command:

      docker-compose -f /opt/mean/docker-compose-production.yml up -d

Note: "/opt/mean" is a git checkout of the public MEAN repository. You can
update to the latest version with "git pull".

* See https://do.co/mean for additional information about this
  one-click installation of MEAN.
* See http://meanjs.org/docs.html#folders for help putting existing
  applications in place.
* See https://github.com/meanjs/mean for information about MEAN in Docker.

The "ufw" firewall is enabled. All ports except for 22, 80, 443 are BLOCKED.
Docker-compose will open and manage public ports for MEAN, including port 3000.

------------------------------------------------------------------------------
To delete this message of the day: rm -rf /etc/update-motd.d/99-one-click

Launching the Sample Project

A sample MEAN project is installed at /opt/mean To launch it, change to that directory and run the startup-command:

  • cd /opt/mean
  • /opt/mean/mean-do.sh

Using the shell script protects your database. Without using the script, MongoDB is publically accessible on the Internet.

The script will continue to run in the foreground, providing console output as you develop and test.

Accessing the Sample Project in a Web Browser

Once launched, you can visit the homepage of the sample project at http://your.ip.address:3000.

Screenshot of the MEAN sample app

Developing your own application

Before starting a new project, it’s good practice to update the Droplet's package information to be sure if you install new packages, you'll get the latest version.

  • apt update

When they update is complete, we will need to install an update to allow tools like NPM and Bower to work.

  • sudo apt-get install nodejs-legacy
  • apt install npm

The MEAN sample project provides you with a template on which to build your application. Let's look at the folder structure:

root@meanjs:/opt/mean# ls
app         config      fig.yml       karma.conf.js  node_modules  Procfile  README.md
bower.json  Dockerfile  gruntfile.js  LICENSE.md     package.json  public    server.js

The app folder contains the server-side Model View Controller (MVC) files. Mongoose is used to communicate with the MongoDB instance which is available at 127.0.0.1:27017

Th config folder contains the configuration files for your application. This includes developer credentials for the social login feature provided by Passport. The template supports five social platforms out of the box: Facebook, Twitter, Google, Linkedin, and Github. If your application needs to send mail, you can also configure your Nodemailer settings here as well.

The public folder contains all of the static files for your application. You can use bower to install additional front-end libraries for use in your app. For instance if you need JQuery, it can be installed with:

  • cd /opt/mean/public
  • npm install -g bower
  • bower --allow-root install jquery

It will now be installed to public/lib/jquery/

Deploying your own

If you already have an application built on the MEAN stack, there's no need to use the sample project. This image provides you with a pre-installed Node environment with MongoDB running on 127.0.0.1:27017

  • rm -r /opt/mean
  • cd /opt/
  • git clone git@github.com:you/your_project.git
  • cd your_project
  • npm install
  • NODE_ENV=production PORT=80 npm start

Further information

For more detailed information on the MEAN stack check out the the docs at Mean.js. To learn more about running MongoDB and Node, check out their respective tags here at DigitalOcean:

23 Comments

Creative Commons License