Like any kind of apps, there are difficult issues to solve when we write Node apps.
In this article, we’ll look at some solutions to common problems when writing Node apps.
We can export an async function like any other function.
For instance, we can write:
async function doSomething() {
// ...
}
module.exports.doSomething = doSomething;
We export doSomething
like we can with any other function.
We can read a file into a base64 string by using the readFileSync
method.
For instance, we can write:
const fs = require('fs');
const str = fs.readFileSync('/path/to/file.jpg', { encoding: 'base64' });
We pass in the 2nd argument with an object.
It has the encoding
property set to 'base64'
so that we can parse the file into a base64 string.
It’s returned and assigned to str
.
#web-development #programming #technology #javascript #software-development