Skip to content

Instantly share code, notes, and snippets.

@rithvikvibhu
Created March 10, 2023 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rithvikvibhu/f6f8a3a785316f02b5d6e06a3c3c9b0f to your computer and use it in GitHub Desktop.
Save rithvikvibhu/f6f8a3a785316f02b5d6e06a3c3c9b0f to your computer and use it in GitHub Desktop.
// run: node api-key.js
const os = require('node:os');
const path = require('node:path');
const bdb = require('bdb');
const BOB_DB_LOC = path.join(os.homedir(), '.config/Bob/db');
const WALLET_API_KEY = 'walletApiKey';
const NODE_API_KEY = 'nodeApiKey';
const db = bdb.create({
createIfMissing: false, // do not create new db if wrong path
location: BOB_DB_LOC,
});
async function get(key) {
const data = await db.get(Buffer.from(key, 'utf-8'));
if (data === null) {
return null;
}
return JSON.parse(data.toString('utf-8'));
}
(async() => {
await db.open();
try {
const nodeApiKey = await get(NODE_API_KEY);
const walletApiKey = await get(WALLET_API_KEY);
console.log('API Keys:');
console.log({nodeApiKey, walletApiKey});
} finally {
await db.close();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment