Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Application configuration.
$ npm install app-etc
var etc = require( 'app-etc' );
Returns an application configuration.
var config = etc();
The function
accepts the following options
:
./etc
.defaults
.dev
.env
.['defaults','user','app','env']
.Note: if a file extension is omitted when specifying file basenames, this module will search for the first file having the basename and a supported extension. For supported extensions, see app-etc-load.
By default, the application configuration directory is a directory named etc
located in the application's root directory. This directory may contain default configuration settings, mappings between environment variables and configuration settings, various application-specific configuration files tailored for different runtime environments, and more. To specify a different directory, set the etc
option:
var config = etc({
'etc': './config'
});
A defaults file should contain default application configuration settings; e.g., if applicable, a default log level, port, etc. By default, this module looks for a file with the basename defaults
. To specify a different basename, set the defaultsFile
option:
var config = etc({
'defaultsFile': 'shared_settings'
});
The user directory option specifies the location of a directory containing user-specific configuration files. The location of this directory is typically OS specific. To specify a directory, set the user
option:
var config = etc({
'user': '/Users/<name>/Library/Preferences'
});
A user file should contain user-specific configuration settings. By default, this module searches for a file having a basename equal to the application name. To specify a different basename, set the userFile
option:
var config = etc({
'userFile': 'configgie.json'
});
Often different runtime environments require different application configurations. For example, in development
, the application may connect to local resources; whereas, in production
, the application may connect to various remote endpoints. To handle the different runtimes, applications will utilize environment specific configuration files; e.g., production.json
, development.json
, test.json
, local.json
, etc. This module sets the default runtime environment to dev
and looks for a corresponding configuration file of the same name in the application configuration directory. To override this option, either set the NODE_ENV
environment variable or set the env
option:
var config = etc({
'env': 'local'
});
Runtime environments (e.g., containers) frequently use environment variables for configuration. To map environment variables to configuration settings, this module searches the application configuration directory for a file which maps each environment variable to a particular setting. By default, this module looks for a file having the basename env
. To specify a different basename, set the envFile
option:
var config = etc({
'envFile': 'env_mapping'
});
The file contents should include each relevant environment variable and a corresponding setting. For example, a JSON mapping file:
{
"GITHUB_API_KEY": {
"keypath": "gKey"
},
"DEBUG_LEVEL": {
"keypath": "logger.level"
},
"PORT": {
"keypath": "server.port",
"type": "number"
},
"SSL_KEY": {
"keypath": "server.key",
"type": "string"
},
"SSL_CERT": {
"keypath": "server.cert",
"type": "string"
}
A TOML mapping file:
# A TOML file which maps environment variables to configuration settings...
[GITHUB_API_KEY]
keypath = "gKey"
# Logger environment variables:
[DEBUG_LEVEL]
keypath = "logger.level"
# Server environment variables:
[PORT]
keypath = "server.port"
type = "number"
[SSL_KEY]
keypath = "server.key"
type = "string"
[SSL_CERT]
keypath = "server.cert"
type = "string"
Notes:
keypath
.keypaths
must be .
separated.type
. Possible types
include:
string
(default)number
boolean
object
error
.Configuration sources are many; e.g., user-specific, application-specific, environment variables, and more. The following sources are supported:
The order
option exists to impose a configuration hierarchy. By default, the hierarchy is
[
'defaults', // read first
'user',
'app',
'env' // read last
]
To specify a different order, set the order
option:
// Only use application and environment variables as configuration sources...
var config = etc({
'order': [
'app',
'env'
]
});
Returns a parser for the specified extension.
var parser = etc.parser( '.json' );
Including the .
when specifying an extension is optional.
var parser = etc.parser( 'json' );
To support additional file formats or to override a parser, provide a parser
function for an associated extension.
var parser = require( 'my-special-fmt-parser' );
etc.parser( '<my-ext>', parser );
Once a parser is set, all configuration instances will parse provided files accordingly.
config.load( './file.<my-ext>' );
For more details, see app-etc-load.
var path = require( 'path' ),
etc = require( 'app-etc' );
var config = etc({
'etc': path.join( __dirname, 'etc' )
});
console.dir( config.get() );
/*
{
'server': {
'port': 8080,
'address': '127.0.0.1',
'ssl': false,
'key': '',
'cert': ''
},
'logger': {
'level': 'debug'
},
'env': 'dev'
}
*/
To run the example code from the top-level application directory,
$ NODE_ENV=dev PORT=8080 node ./examples/index.js
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
Copyright © 2015. Athan Reines.
FAQs
Application configuration.
The npm package app-etc receives a total of 0 weekly downloads. As such, app-etc popularity was classified as not popular.
We found that app-etc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.