Skip to content

Instantly share code, notes, and snippets.

@26medias
Created February 9, 2024 15:49
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 26medias/fae3ec365c40b8fda0add1b05bc4c01e to your computer and use it in GitHub Desktop.
Save 26medias/fae3ec365c40b8fda0add1b05bc4c01e to your computer and use it in GitHub Desktop.
env to .env
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let inputData = '';
rl.on('line', (input) => {
inputData += input + '\n';
if (input === '' && inputData.endsWith('\n\n')) {
const envLines = inputData.trim().split('\n');
const convertedLines = envLines.map(line => {
const match = line.match(/"([^"]+)":\s*(.+)/);
return match ? `${match[1]}=${match[2]}` : '';
}).filter(line => line);
console.log(convertedLines.join('\n'));
rl.close();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment