Skip to content

Instantly share code, notes, and snippets.

@anshumanb
Last active December 19, 2021 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anshumanb/a6d3e687eb56be3269385004c677f184 to your computer and use it in GitHub Desktop.
Save anshumanb/a6d3e687eb56be3269385004c677f184 to your computer and use it in GitHub Desktop.
NodeJS read/write JSON
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