Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Copin - opinionated config for node..
Copin is a fairly simple config loader. It will read and merge:
dev-build, woteva-custom
By default variables from the shell environment are not included in the config when NODE_ENV is 'test'.
Config loading
By default:
$ yarn add copin lodash
// or
$ npm i -S copin lodash
Create config files in your app
The config directory is config
by default, but this can be customised when
creating the Copin instance with the dir
option.
my-app
├── config/
│ ├── default.ts
│ ├── ENV_MAP.ts
│ ├── local.ts
│ ├── production.ts
│ ├── test.ts
│ └── types.ts
├── src/
├── .gitignore
└── README.md
.gitignore:
config/local.ts
config/default.ts:
import { Config } from "../types";
const config: Partial<Config> = {
server: {
host: "localhost",
port: "8080",
log_level: "info"
}
};
export { config }
config/production.ts:
import { RecursivePartial } from "copin";
import { Config } from "../types";
const config: RecursivePartial<Config> = {
server: {
host: "myapp",
port: "80",
}
};
export { config }
config/test.ts:
import { RecursivePartial } from "copin";
import { Config } from "../types";
const config: RecursivePartial<Config> = {
server: {
log_level: "fatal"
}
};
export { config }
config/ENV_MAP.ts:
import { RecursivePartial } from "copin";
import { Config } from "../types";
const config: RecursivePartial<Config> = {
server: {
host: "MY_APP_HOST",
}
};
export { config }
using the config files from above..
bare start
npm start
{
server: {
host: "localhost",
port: "8080",
log_level: "info"
}
}
start with environment variable
MY_APP_HOST=app-host npm start
app-host
.{
server: {
host: "app-host",
port: "8080",
log_level: "info"
}
}
start in production with environment variable
MY_APP_HOST=app-host NODE_ENV=production npm start`
app-host
.{
server: {
host: "app-host",
port: "80",
log_level: "info"
}
}
start in test with environment variable
MY_APP_HOST=app-host NODE_ENV=test npm start`
{
server: {
host: "localhost",
port: "8080",
log_level: "fatal"
}
}
add a local config
config/local.ts:
import { Config } from "../types";
const config: Partial<Config> = {
server: {
port: "8765",
}
};
export { config }
{
server: {
host: "localhost",
port: "8765",
log_level: "info"
}
}
Import Copin
import copin from 'copin';
Usage
const config = copin();
const serverHost = config.server.host;
server.start(serverHost);
copin();
copin({ dir, reload, fileOnlyNodeEnv, noNodeEnvConfig, isGlobal });
Get an instance of Copin. In normal use it's likely you will not need to specify any options unless your config files are located somewhere other than the config directory.
var config = copin({ dir: 'copin/config/files' });
option | type | description |
---|---|---|
dir | String | relative path to the config directory. defaults to config |
reload | Boolean | if true , config will be reloaded. defaults to false |
includeEnvMapInTest | Boolean | if true , env map values will be included in test mode. defaults to false |
includeLocalInTest | Boolean | if true , local.ts values will be included in test mode. defaults to false |
alertNoNodeEnvConfig | String | what to do if there is no config for the current NODE_ENV. May be null , 'warn' , or 'error' . Defaults to null . |
isGlobal | Boolean | if true then imports of the same installation of Copin will share the config object. Defaults to true |
extConfig | Object | if you have config from other sources you can include them here. They will override all config values except those from environmental variables mapped by ENV_MAP. |
May be freely distributed under the MIT license.
Copyright (c) 2017 Jason Galea
FAQs
Opinionated Config for Typescript/Node apps
The npm package copin receives a total of 1 weekly downloads. As such, copin popularity was classified as not popular.
We found that copin 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.