Monday, 3 August 2020

log analyzer tool for linux - GoAccess

log analyzer tool for linux - GoAccess

Question: What is GoAccess in linux?
GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal.

Question: How GoAccess works?
It analyse the Log file (access.log) which is cotinue in writes by application.

Question: What are the benefits of GoAccess?
  1. Completely Real Time
  2. Nearly All Web Log Formats
  3. Track Application Response Time
  4. Incremental Log Processing
  5. Minimal configuration needed
  6. Visitors
  7. Color Scheme Customizable

Question: Does GoAccess is available for GUI?
Yes, You can watch in Terminal and GUI.

How to install GoAccess in Server?
git clone
cd goaccess
autoreconf -fi
./configure --enable-geoip --enable-utf8

How to run GoAccess to check the analytics?
goaccess access.log -c

How to check the analytics in HTML page?
goaccess access.log -o report.html --log-format=COMBINED

Now run,

How to check the analytics in HTML page dynamically?
goaccess access.log -o /var/www/html/dynamic.html --log-format=COMBINED --real-time-html

Now run,

Question: Share the Offical website link?

Wednesday, 29 July 2020

How do I manage MongoDB connections in a Node.js web application?

How do I manage MongoDB connections in a Node.js web application?

Question: How do I manage MongoDB connections in a Node.js web application?
You need to install mongoose and bluebird module.
Also you must have mongodb install in server, As you need mongodb URL and port on which mongodb running.

var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
//mongodb connection with error handing
mongoose.connect(config.MONGO_DB_URL + config.MONGO_DB);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
    console.log("MongoDB connected Successfully.!");

Question: mongoose - find all documents with IDs listed in array?
var AjaxChatUser = mongoose.model('AjaxChatUser');
    '_id': { $in: [
}, function(err, docs){

Question: How to npm install to a specified directory?
Use --prefix option, to installed in specific directory.
npm install --prefix  -g

Question: How to declare multiple module.exports in Node.js?
You can put multiple function inside module.exports.

module.exports = {
    method: function() {},
    otherMethod: function() {},

Question: Can we write a JS code that work for both (node and the browser)?
Yes, We can write.
Suppose we have mymodule.js which have following code.
Example of Code
   exports.test1 = function(){
        return 'this is test1 function.'
   exports.test2 = function(){
        return 'this is test2 function.'

})(typeof exports === 'undefined'? this['mymodule']={}: exports);

In Node (Server side()
var share = require('./mymodule.js');

In Browser (Client side()
//Include the js with script tag

Question: How we can use global variable in Node?
We can use with global.varname

Question: How we can access static files with express.js in Node?
Use following to set the folder as static so that we can put public files here.
app.use(express.static('public')); //public folder