Created
March 10, 2023 17:27
-
-
Save rithvikvibhu/f6f8a3a785316f02b5d6e06a3c3c9b0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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