Remote Dotenv server/client for Node.js
This project aims for minimal dependencies & light weight.
Helps you easily share environment variables in various distributed service structures.
This project is currently in development.
If you expose remote-env to an external network, you must specify an authentication method for security purposes.
- ES2020 Node.js 20.x
npm install @vientorepublic/remote-env
import { remoteEnvProvider, remoteEnvClient } from '@vientorepublic/remote-env';
// For CommonJS:
// const { remoteEnvProvider, remoteEnvClient } = require('@vientorepublic/remote-env');
const server = new remoteEnvProvider();
server.createServer('127.0.0.1', 8080);
const client = new remoteEnvClient();
client.connect('127.0.0.1', 8080);
// getEnv(key: string): Promise<string | null>
const value = await client.getEnv('KEY');
console.log(value);
client.close();
server.close();
Note
This option is highly recommended as it encrypts your data with the RSA algorithm.
import { readFileSync } from 'node:fs';
const publicKey = readFileSync('public_key.pem', 'utf8');
const privateKey = readFileSync('private_key.pem', 'utf8');
const server = new remoteEnvProvider();
server.createServer('127.0.0.1', 8080, {
auth: {
encryption: {
publicKey,
},
},
});
const client = new remoteEnvClient();
client.connect('127.0.0.1', 8080, {
auth: {
encryption: {
publicKey,
privateKey,
},
},
});
- Generate RSA 2048Bit Private Key:
openssl genrsa -out private_key.pem 2048
- Extract public key from private key:
openssl rsa -in private_key.pem -out public_key.pem -pubout
Warning
Password Authentication will be deprecated. This option does not encrypt your data.
const server = new remoteEnvProvider();
server.createServer('127.0.0.1', 8080, {
auth: {
password: 'my-supersecret-password@!',
},
});
const client = new remoteEnvClient();
client.connect('127.0.0.1', 8080, {
auth: {
password: 'my-supersecret-password@!',
},
});