# all files / node-ipc/entities/ Defaults.js

90% Statements 9/10
57.14% Branches 4/7
100% Functions 2/2
90% Lines 9/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140

    1×

    1×

    1×

    1×
    1×
    1×
    1×

    1×

    1×
     'use strict';

    /*eslint no-magic-numbers: ["error", { "ignore": [ 0] }]*/

    /**
     * @module entities
     */

    const os = require('os');

    /**
     * @class Defaults
     * @description Defaults Entity
     */
    class Defaults{

        /**
         * @constructor
         * @method constructor
         * @return {void}
         */
        constructor(){

            Object.defineProperties(
                this,
                {
                    appspace        : {
                        enumerable:true,
                        writable:true,
                        value:'app.'
                    },
                    socketRoot      : {
                        enumerable:true,
                        writable:true,
                        value:'/tmp/'
                    },
                    networkHost     : {
                        enumerable:true,
                        writable:true,
                        value: ''
                    },
                    networkPort     : {
                        enumerable:true,
                        writable:true,
                        value:8000
                    },
                    id              : {
                        enumerable:true,
                        writable:true,
                        value:os.hostname()
                    },
                    encoding        : {
                        enumerable:true,
                        writable:true,
                        value:'utf8'
                    },
                    rawBuffer       : {
                        enumerable:true,
                        writable:true,
                        value:false
                    },
                    sync            : {
                        enumerable:true,
                        writable:true,
                        value:false
                    },
                    silent          : {
                        enumerable:true,
                        writable:true,
                        value:false
                    },
                    logDepth:{
                        enumerable:true,
                        writable:true,
                        value:5
                    },
                    logInColor:{
                        enumerable:true,
                        writable:true,
                        value:true
                    },
                    maxConnections  : {
                        enumerable:true,
                        writable:true,
                        value:100
                    },
                    retry           : {
                        enumerable:true,
                        writable:true,
                        value:500
                    },
                    maxRetries      : {
                        enumerable:true,
                        writable:true,
                        value:Infinity
                    },
                    stopRetrying    : {
                        enumerable:true,
                        writable:true,
                        value:false
                    },
                    IPType          : {
                        enumerable:true,
                        writable:true,
                        value: getIPType()
                    },
                    tls             : {
                        enumerable:true,
                        writable:true,
                        value:false
                    }
                }
            );

            this.networkHost = (this.IPType == 'IPv6') ? '::1' : '127.0.0.1';
        }
    }

    /**
     * method to get ip type
     *
     * @method getIPType
     * @return {string} ip type
     */
    function getIPType() {
        const networkInterfaces = os.networkInterfaces();
        let IPType = '';
        Iif (networkInterfaces
            && Array.isArray(networkInterfaces)
            && networkInterfaces.length > 0) {
            // getting the family of first network interface available
            IPType = networkInterfaces [
                Object.keys( networkInterfaces )[0]
            ][0].family;
        }
        return IPType;
    }

    module.exports=Defaults;