Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "convict in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'convict' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

},
    host: {
      doc: 'Optional. URL to remote docker host',
      format: String,
      default: undefined
    },
    port: {
      doc: 'Optional. Port on remote docker host',
      format: 'port_or_windows_named_pipe',
      default: undefined
    }
  }
});

// Load environment dependent configuration
convict.addParser({ extension: ['yml', 'yaml'], parse: yaml.safeLoad });
var config_dir = process.env.config_dir || "./config";
console.log("Loading settings from " + config_dir);

//Check if the configuration file exists, if it doesn't then skip this
try{
  if (fs.existsSync(config_dir + '/configuration.yaml')) {
    config.loadFile(config_dir + '/configuration.yaml');
  }
} catch(err) {
  console.warn("No configuration file detected. Using default settings");
}

// Perform validation
config.validate({allowed: 'warn'});

module.exports = config;
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import convict from 'convict';
import fs from 'fs';
import path from 'path';

const conf = convict({
  authHeader: {
    default: 'oidc-claim-id-token-email',
    doc: 'Authentication header that should be logged for the user',
    env: 'AUTH_HEADER',
    format: String,
  },
  authdbUrl: {
    default: 'http://localhost:8000',
    doc: 'fxa-auth-db-mysql url',
    env: 'AUTHDB_URL',
    format: String,
  },
  env: {
    default: 'production',
    doc: 'The current node.js environment',
    env: 'NODE_ENV',
function validateConfig(
    cluster: { isMaster: boolean },
    schema: convict.Schema,
    namespaceConfig: any
) {
    try {
        const config = convict(schema || {});
        config.load(namespaceConfig);

        if (cluster.isMaster) {
            config.validate({
                // IMPORTANT: changing this will break things
                // FIXME
                // false is deprecated and will be removed in ^5.0.0
                // must be warn or strict
                allowed: true,
            } as any);
        }

        return config.getProperties();
    } catch (err) {
        throw new TSError(err, { reason: 'Error validating configuration' });
    }
if (statFile.isFile()) {
        convict.addFormats(require(formatsFile));
    }
} catch (e) {}

// check and load convict schema
const schemaFile = path.resolve(configDir, 'schema.js');
try {
    const statFile = fs.statSync(schemaFile);
    if (!statFile.isFile()) {
        throw new Error('Not a file');
    }
} catch (e) {
    throw new Error(`[rob-config] Schema file "${e.path}" does not exists.`);
}
const conf = convict(require(schemaFile));

// check and load related environment config
const env = process.env.NODE_ENV || 'development';
const configFile = path.resolve(configDir, env + '.js');
try {
    const statFile = fs.statSync(configFile);
    if (!statFile.isFile()) {
        throw new Error('Not a file');
    }
} catch (e) {
    throw new Error(`[rob-config] Config file "${e.path}" does not exists.`);
}
const envConf = require(configFile);
conf.load(envConf);

// export utility methods and current config properties
import convict from "convict";
import Joi from "joi";

// Add custom format for the mongo uri scheme.
convict.addFormat({
  name: "mongo-uri",
  validate: (url: string) => {
    Joi.assert(
      url,
      Joi.string().uri({
        scheme: ["mongodb"],
      })
    );
  },
});

// Add custom format for the redis uri scheme.
convict.addFormat({
  name: "redis-uri",
  validate: (url: string) => {
    Joi.assert(
// Add custom format for the redis uri scheme.
convict.addFormat({
  name: "redis-uri",
  validate: (url: string) => {
    Joi.assert(
      url,
      Joi.string().uri({
        scheme: ["redis"],
      })
    );
  },
});

// Add a custom format for the optional-url that includes a trailing slash.
convict.addFormat({
  name: "optional-url",
  validate: (url: string) => {
    if (url) {
      Joi.assert(url, Joi.string().uri());
    }
  },
  // Ensure that there is an ending slash.
  coerce: (url: string) => (url ? ensureEndSlash(url) : url),
});

// Add a custom format that is a duration parsed with `ms` to used instead of
// the default format which will use `moment`.
convict.addFormat({
  name: "ms",
  validate: (val: number) => {
    Joi.assert(val, Joi.number().min(0));
const configDir = process.env.ROB_CONFIG_DIR || 'config';
try {
    const statDir = fs.statSync(configDir);
    if (!statDir.isDirectory()) {
        throw new Error('Not a directory');
    }
} catch (e) {
    throw new Error(`[rob-config] Config directory "${e.path}" does not exists.`);
}

// check and load convict formats if availables
const formatsFile = path.resolve(configDir, 'formats.js');
try {
    const statFile = fs.statSync(formatsFile);
    if (statFile.isFile()) {
        convict.addFormats(require(formatsFile));
    }
} catch (e) {}

// check and load convict schema
const schemaFile = path.resolve(configDir, 'schema.js');
try {
    const statFile = fs.statSync(schemaFile);
    if (!statFile.isFile()) {
        throw new Error('Not a file');
    }
} catch (e) {
    throw new Error(`[rob-config] Schema file "${e.path}" does not exists.`);
}
const conf = convict(require(schemaFile));

// check and load related environment config
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const convict = require('convict');
convict.addParser({extension: ['yml', 'yaml'], parse: yaml.safeLoad});

const config = convict({
  application: {
    config: {
      doc: 'name of the config to load',
      format: function check(val) {
        if (!/^.+$/.test(val)) {
          throw new Error('must be a string or number');
        }
      },
      default: 'default',
      env: 'CONFIG',
      arg: 'config',
    },
    debug: {
      doc: 'enable debug',
module.exports = (config) => {
  const {create, formats} = createFormatCollection();

  visitConfig({
    default: (v, node) => {
      const result = isObjectHash(v) && v.default;
      node.isRequired = (result === null);
      node.isOptional = (result !== null);
      return result;
    },
    format: v => (typeof v === 'string') ? v : create([].concat(v))
  })(config);

  convict.addFormats(formats);

  const instance = convict(config);

  try {
    instance.validate({allowed: 'strict'});
  } catch ({message}) {
    instance.set(
      'errors',
      message
        .split('\n')
        .map(v => v.split(':').map(vv => vv.trim()))
        .reduce((r, [k, v]) => Object.assign(r, {[k]: v}), {})
    );
  }

  return {
import path from 'path'
import convict from 'convict'
import url from 'url'

const workers = 3
const maxConnectionsAllowed = 20
const freeConnectionsForThirdTools = 2

const config = convict({
  env: {
    doc: 'The application environment',
    format: ['production', 'development', 'test'],
    default: 'development',
    env: 'NODE_ENV',
  },
  appBaseUrl: {
    doc: 'Base URL',
    format: String,
    default: 'http://localhost:8080',
    env: 'APP_BASE_URL',
  },
  server: {
    port: {
      doc: 'The server port number',
      format: 'port',

Is your System Free of Underlying Vulnerabilities?
Find Out Now