Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@elite-libs/auto-config
Advanced tools
A Unified Config & Arguments Library for Node.js. Featuring support for environment variables, command line arguments, and JSON files!
A Unified Config & Arguments Library for Node.js!
Featuring support for environment variables, command line arguments, and (soon) JSON/YAML/INI files!
There are so many config libraries, do we really need another??? Well, possibly!
No existing library I tried met my requirements.
My goals & requirements include:
Table of Contents
npm install @elite-libs/auto-config
yarn add @elite-libs/auto-config
// `./src/aws-config.ts`
import { autoConfig } from '@elite-libs/auto-config';
import AWS from 'aws-sdk';
const awsConfig = getAwsConfig();
AWS.config.update({
...awsConfig,
endpointDiscoveryEnabled: true,
});
function getAwsConfig() {
return autoConfig({
region: {
help: 'AWS Region',
args: ['--region', '-r', 'AWS_REGION'],
default: 'us-west-1',
required: true,
},
accessKeyId: {
help: 'AWS Access Key ID',
args: ['--access-key-id', 'AWS_ACCESS_KEY_ID'],
required: true,
},
secretAccessKey: {
help: 'AWS Secret Access Key',
args: ['--secret-access-key', 'AWS_SECRET_ACCESS_KEY'],
required: true,
},
});
}
// `./src/config.ts`
import { autoConfig } from '@elite-libs/auto-config';
export default autoConfig({
databaseUrl: {
help: 'The Postgres connection string.',
args: ['--databaseUrl', '--db', 'DATABASE_URL'],
required: true,
},
port: {
help: 'The port to start server on.',
args: ['--port', '-p', 'PORT'],
type: 'number',
required: true,
},
debugMode: {
help: 'Debug mode.',
args: ['--debug', '-D'],
type: 'boolean',
default: false,
},
});
// `./src/server.js`
import express from 'express';
import catRouter from './routes/cat';
import config from './config';
const { port, debugMode } = config;
const logMode = debugMode ? "dev" : "combined";
export const app = express()
.use(express.json())
.use(express.urlencoded({ extended: false }))
.use(morgan(logMode))
.get('/', (req, res) => res.send('Welcome to my API'))
.use('/cat', catRouter);
app.listen(port)
.on('error', console.error)
.on('listening', () =>
console.log(`Started server: http://0.0.0.0:${port}`);
);
const moveOptions = autoConfig({
force: {
args: '-f',
help: 'Do not prompt for confirmation before overwriting the destination path. (The -f option overrides any previous -i or -n options.)'
type: 'boolean',
},
interactive: {
args: '-i',
help: 'Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file. If the response from the standard input begins with the character `y` or `Y`, the move is attempted. (The -i option overrides any previous -f or -n options.)'
type: 'boolean',
},
noOverwrite: {
args: '-n',
help: 'Do not overwrite an existing file. (The -n option overrides any previous -f or -i options.)',
type: 'boolean',
},
verbose: {
args: '-v',
help: 'Cause mv to be verbose, showing files after they are moved.',
type: 'boolean',
}
});
// `./src/config/featureFlags.ts`
export const Flags = autoConfig({
dashboard: {
args: ['FEATURE_FLAG_DASHBOARD'],
type: 'enum',
enum: ['off', 'variant1'],
default: 'off',
},
checkout: {
args: ['FEATURE_FLAG_CHECKOUT'],
type: 'enum',
enum: ['off', 'variant1', 'variant2'],
default: 'off',
},
register: {
args: ['FEATURE_FLAG_REGISTER'],
type: 'enum',
enum: ['off', 'variant1', 'variant2', 'variant3', 'variant4'],
default: 'off',
},
});
node ./src/app.js \
--port 8080 \
--databaseUrl 'postgres://localhost/postgres' \
--debug
# { port: 8080, databaseUrl: 'postgres://localhost/postgres', debug: true }
DATABASE_URL=postgres://localhost/postgres \
node ./src/app.js \
--port 8080 \
--debug
# { port: 8080, databaseUrl: 'postgres://localhost/postgres', debug: true }
node ./src/app.js \
-D \
--port 8080 \
--databaseUrl 'postgres://localhost/postgres'
# { port: 8080, databaseUrl: 'postgres://localhost/postgres', debug: true }
node ./src/app.js \
--port 8080
# Error: databaseUrl is required.
node ./src/app.js --help
╭───────────────────────────┬────────────────────────────────────────────┬──────────────────────────────────────────────────────────╮
│ │ │ │
│ Name │ Help │ CLI Args, Env Name(s) │
│ │ │ │
├───────────────────────────┼────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│databaseUrl* │The Postgres connection string. │--databaseUrl, DATABASE_URI, DATABASE_URL │
├───────────────────────────┼────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│port* │The port to serve content from. │-p, --port │
├───────────────────────────┼────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│[debugMode] = false │Debug mode. │-D, --debug │
├───────────────────────────┼────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│help │Show this help. │--help │
├───────────────────────────┼────────────────────────────────────────────┼──────────────────────────────────────────────────────────┤
│version │Show the current version. │--version │
╰───────────────────────────┴────────────────────────────────────────────┴──────────────────────────────────────────────────────────╯
export const config = autoConfig({
"databaseUrl": ['--databaseUrl', '--db', 'DATABASE_URL'],
"port": ['--port', '-p', 'PORT'],
"debug": ['--debug', '-D'],
});
() => process.env.FEAT_FLAG_V1
. To support non-dynamic env references.--help
output.
DESCRIPTION
, Usage
, etc._
or __
args from minimist. (Overflow/unparsed extra args.)--no-debug
versus --debug
.{ssm:/app/flags/path/admin_dashboard}
['{ssm:/app/flags/path/admin_dashboard}', 'FLAG_ADMIN_DASHBOARD_ENABLED', '--flagAdminDashboard', '--flag-admin-dashboard']
{config.flags.admin_dashboard}
['{config.flags.admin_dashboard}', 'FLAG_ADMIN_DASHBOARD_ENABLED', '--flagAdminDashboard', '--flag-admin-dashboard']
--version
output.default
values.required
values.optional
, min
, max
, gt
, gte
, lt
, lte
.Projects researched, with any notes on why it wasn't a good fit.
default
helper function to check for env keys. Or we could transform yargs config into overlapping format.FAQs
A Unified Config & Arguments Library for Node.js. Featuring support for environment variables, command line arguments, and JSON files!
The npm package @elite-libs/auto-config receives a total of 2 weekly downloads. As such, @elite-libs/auto-config popularity was classified as not popular.
We found that @elite-libs/auto-config 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.