Last active
December 19, 2021 23:27
-
-
Save anshumanb/a6d3e687eb56be3269385004c677f184 to your computer and use it in GitHub Desktop.
NodeJS read/write JSON
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
const fs = require("fs/promises"); | |
const readJson = async (filePath) => | |
JSON.parse(await fs.readFile(filePath, "utf-8")); | |
const writeJson = async (filePath, data) => | |
fs.writeFile(filePath, JSON.stringify(data, null, 2).concat("\n"), "utf-8"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment