Created
December 1, 2021 23:57
-
-
Save DiegoVictor/81e758af99bd7d414eb976fe1ce2945d to your computer and use it in GitHub Desktop.
Convert image to base64 using Node.js' native libs
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
// Usage: node converter.js <file path> | |
const { | |
promises: { readFile, writeFile }, | |
} = require("fs"); | |
const [, , filePath] = process.argv; | |
async function converter(path) { | |
return readFile(path) | |
.then((buffer) => | |
writeFile( | |
"base64.txt", | |
buffer.toString("base64") | |
) | |
); | |
} | |
converter(filePath).then(() => { | |
process.stdout.write(`\nOutput:\n${__dirname}\\base64.txt\n`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment