Created
June 22, 2022 01:47
-
-
Save ehizman/8bca4ce27c1c3612462b630c4f6f99da to your computer and use it in GitHub Desktop.
write to files in js
This file contains hidden or 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"); | |
| //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