Skip to content

Instantly share code, notes, and snippets.

@ehizman
Created June 22, 2022 01:47
Show Gist options
  • Select an option

  • Save ehizman/8bca4ce27c1c3612462b630c4f6f99da to your computer and use it in GitHub Desktop.

Select an option

Save ehizman/8bca4ce27c1c3612462b630c4f6f99da to your computer and use it in GitHub Desktop.
write to files in js
const fs = require("fs");
//write to file sychronously
const dataToWrite = "Hello there by injection";
fs.writeFileSync(`${__dirname}/data.txt`, dataToWrite, "utf-8");
//write to file asynchronously
const dataToWriteAsync = "Hello there by injection async";
fs.writeFile(`${__dirname}/data.txt`, dataToWriteAsync, "utf-8", (err) => {
if (!err) console.log("Done!");
else console.log("Error: " + err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment