Sample code for 30+ languages & platforms
Node.js

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

    var bd = new chilkat.BinData();

    success = bd.LoadFile("qa_data/jpg/starfish.jpg");
    if (success == false) {
        console.log("Failed to load file.");
        return;
    }

    console.log(bd.GetEncoded("base64"));

    // If you want mult-line base64:
    console.log("--");
    console.log(bd.GetEncoded("base64_mime"));

    // If you want hex..
    console.log("--");
    console.log(bd.GetEncoded("hex"));

    // etc.

}

chilkatExample();