writeJsonToFile
Write JSON data to a file to retrieve later via readJsonFromFile.

Returns

(Promise<void>): A promise that fulfills without arguments when writing has finished.

Example

1
import lampix from '@lampix/core';
2
3
const data = {
4
answerToLife: 42
5
};
6
7
lampix.writeJsonToFile('answers.json', data)
8
.then(() => console.log('Successfully saved all answers.'));
Copied!

Notes

localStorage API is also enabled. You can use it instead of this method. localStorage, by design, is a blocking I/O operation (synchronous). Use writeJsonToFile and readJsonFromFile if you want to use non-blocking (asynchronous) I/O operations.
writeJsonToFile (like localStorage), is application specific. This means one application cannot retrieve the saved data of another application.
Copy link