How To Install MEAN on Ubuntu 20.04

MEAN is a Java-Script FOSS for developing web applications and a web interface. On the stack, MEAN supports JavaScript software, which means that only one language is required for development on the server (backend) and website (web interface). MEAN stands for MongoDB, ExpressJS, AngularJS, and NodeJS, which are separate technologies.

Install MongoDB

Already on the existing server Ubuntu 20.04 must first install MongoDB

$ sudo apt update && sudo apt install -y mongodb

Next, launch and enable MongoDB at boot.

$ sudo systemctl start mongodb
$ sudo systemctl enable mongodb

Install NodeJS and Dependencies

Using the official source script mode to get the latest version of NodeJS.

$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

Install NodeJS, build dependencies and git

$ sudo apt install -y nodejs gcc g++ make git

Use npm to set yarn and a sip

$ sudo npm install -g yarn
$ sudo npm install -g gulp

Clone the official MeanJS repository

$ git clone https://github.com/meanjs/mean

Go to the MeanJS directory

$ cd mean

Set the dependencies using yarn.

$ yarn install

Test

Open the server.js file

$ nano server.js

Then you need to replace the contents with the following code:

const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const app = express();

app.use('/', (req, res) => {
    MongoClient.connect("mongodb://localhost:27017/test", function(err, db){
        db.collection('Example', function(err, collection){
            collection.insert({ pageHits: 'pageHits' });
            db.collection('Example').count(function(err, count){
                if(err) throw err;
                res.status(200).send('Page Hits: ' + Math.floor(count/2));
            });
        });
    });
});

app.listen(3000);
console.log('Server running at http://localhost:3000/');

module.exports = app;

Start the server

$ gulp

In the end, in order to make sure that the server is working properly and that the databases are handled correctly, you need to go to the URL of your page. Replace 192.168.8.8 with your north IP

http://192.168.0.123:3000/

Was this article helpful?

Related Articles

1 Comment

  1. 3M 9502

    I would say this is one. From beginning to end you nailed it.
    To write this you might have worked for study.
    King regards,
    Lunding Raahauge