MEAN is an open-source JavaScript framework for developing both front-end and back-end web applications. This framework allows for the creation of website frontend and backend programs using only JavaScript. MEAN stands for MongoDB, Express, Angular, and Node.js. These are independent technologies that, when integrated, provide enhanced functionality. First, we need to prepare a cloud server with Ubuntu 20.04 operating system installed and update it with the latest patches.
Execute the following commands to install MongoDB and start MongoDB.
$ sudo apt install -y mongodb
$ sudo systemctl start mongodb
$ sudo systemctl enable mongodb
Use the official NodeSource repository to install the latest version of Node.js.
$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
$ sudo apt install -y nodejs gcc g++ make git
Install yarn and gulp using npm.
$ sudo npm install -g yarn
$ sudo npm install -g gulp
Clone the official MeanJS repository and use yarn to install the dependencies.
$ git clone https://github.com/meanjs/mean
$ cd mean
$ yarn install
Edit the server.js file.
$ nano server.js
Add the following code to the server.js file.
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;
Finally, compile using the gulp tool.
$ gulp
To verify that the server is running correctly and the database is connecting properly, visit: http://192.168.0.123:3000. If the message "Page Hits:" appears, it indicates that the MEAN platform has been successfully installed. Replace 192.168.0.123 with the actual IP address."
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58