How to use the convict function in convict

To help you get started, we’ve selected a few convict examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fxa / packages / fxa-support-panel / config / index.ts View on Github external
/* 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',
github terascope / teraslice / packages / terafoundation / src / validate-configs.ts View on Github external
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' });
    }
github jeromemacias / node-rob-config / src / index.js View on Github external
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
github smooth-code / bundle-analyzer / apps / server / src / config.js View on Github external
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',
github reindexio / reindex-api / server / Config.js View on Github external
import Path from 'path';

import convict from 'convict';
import Cryptiles from 'cryptiles';
import { isPlainObject, isString, values } from 'lodash';

import DatabaseTypes from '../db/DatabaseTypes';

const Config = convict({
  connection: {
    port: {
      default: 5000,
      doc: 'The TCP port the connection will listen to.',
      env: 'PORT',
      format: 'port',
    },
    routes: {
      cors: true,
      files: {
        relativeTo: Path.join(__dirname, '..', 'public'),
      },
    },
  },
  app: {
    key: {
github coralproject / talk / src / core / build / config.ts View on Github external
import convict from "convict";

import { LOCALES } from "../common/helpers/i18n/locales";

const config = convict({
  env: {
    doc: "The application environment.",
    format: ["production", "development", "test"],
    default: "development",
    env: "NODE_ENV",
  },
  port: {
    doc: "The port the server is bound to",
    format: "port",
    default: 3000,
    env: "PORT",
    arg: "port",
  },
  dev_port: {
    doc: "The port to bind for the Webpack Dev Server.",
    format: "port",
github marmelab / web-myna / src / config.js View on Github external
validate: (apis, schema) => {
        if (!Array.isArray(apis)) {
            throw new Error('must be of type Array');
        }

        apis.map((api, index) => {
            const tokenName = api.name ? `${api.name.toUpperCase().replace(/-/g, '_')}_TOKEN` : null;
            signale.debug(tokenName);
            if (tokenName || isPlayerMode) {
                const apiToken = processEnv[tokenName];
                apis[index].token = isPlayerMode ? 'webMynaPlayerToken' : apiToken;
            }
        });

        for (const api of apis) {
            convict(schema.children)
                .load(api)
                .validate();
        }
    },
});
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / config / config.js View on Github external
import convict from 'convict';

const config = convict({
  logLevel: {
    doc: 'The logging level',
    format: 'String',
    default: 'info',
    env: 'LOG_LEVEL',
  },
  datalabDomain: {
    doc: 'The domain the datalabs instance is running on',
    format: 'String',
    default: 'datalabs.localhost',
    env: 'DATALAB_DOMAIN',
  },
  apiPort: {
    doc: 'The port for the API service',
    format: 'port',
    default: 8003,
github coralproject / talk / src / core / server / config.ts View on Github external
coerce: (val: string) => ms(val),
});

const algorithms = [
  "HS256",
  "HS384",
  "HS512",
  "RS256",
  "RS384",
  "RS512",
  "ES256",
  "ES384",
  "ES512",
];

const config = convict({
  env: {
    doc: "The application environment.",
    format: ["production", "development", "test"],
    default: "development",
    env: "NODE_ENV",
  },
  default_locale: {
    doc:
      "Specify the default locale to use for all requests without a locale specified",
    format: LOCALES,
    default: "en-US",
    env: "LOCALE",
  },
  trust_proxy: {
    doc:
      'When provided, it configures the "trust proxy" settings for Express (See https://expressjs.com/en/guide/behind-proxies.html)',
github argos-ci / argos / src / config.js View on Github external
import path from 'path'
import convict from 'convict'
import dotenv from 'dotenv'

dotenv.config()

const config = convict({
  env: {
    doc: 'The application environment',
    format: ['production', 'development', 'test'],
    default: 'development',
    env: 'NODE_ENV',
  },
  googleAnalytics: {
    doc: 'The tracking id',
    default: 'UA-89989315-2',
  },
  api: {
    subdomain: {
      format: String,
      default: 'api.dev',
      env: 'API_SUBDOMAIN',
    },

convict

Featureful configuration management library for Node.js (nested structure, schema validation, etc.)

Apache-2.0
Latest version published 1 year ago

Package Health Score

63 / 100
Full package analysis