Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Dev #1

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 2, 2021

No description provided.

@@ -0,0 +1,2 @@
node_module
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be node_modules

Suggested change
node_module
node_modules

@@ -1,24 +1,29 @@
const crypto = require('crypto');
const https = require('https');
require('dotenv').config();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require('dotenv').config();
const nconf = require('nconf');

Comment on lines +5 to +6
const apiKey = process.env.API_KEY;
const privateKey = process.env.PRIVATE_KEY;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using nconf over dotenv, it's far more "12 factor" and a better user experience.

Suggested change
const apiKey = process.env.API_KEY;
const privateKey = process.env.PRIVATE_KEY;
const ENV_SEPARATOR = '__';
const KEY = 'btcmarkets';
const ENV_PATTERN = new RegExp(`/^${KEY.toUpperCase()}${ENV_SEPARATOR}/`);
nconf
.env({
separator: ENV_SEPARATOR,
match: ENV_PATTERN,
lowerCase: true,
parseValues: true,
transform(obj) {
obj.key.replace(ENV_PATTERN, '');
return obj;
},
})
.argv({
apiKey: {
describe: 'prefix of all new packages created',
},
privateKey: {
describe: 'prefix of all new packages created',
}
});
const apiKey = nconf.get('apiKey');
const privateKey = nconf.get('privateKey');

Now the cli is used like this:

node client.js --apiKey=something --privateKey=another-thing

or

BTCMARKETS_API_KEY=something \
BTCMARKETS_API_PRIVATE=another-thing \
node client.js 

you'll also get :

node client.js --help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant