Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
write-to-file
Advanced tools
Writes data to file and automatically create its directories if not exists
Writes data to file and automatically create its directories if not exists.
$ npm install write-to-file
# Or if you use Yarn
$ yarn add write-to-file
const writeToFile = require("write-to-file");
(async () => {
try {
await writeToFile("foo/bar/baz.txt", "Hello World!");
} catch(error) {
console.error(error.message);
}
})();
If foo/bar
directory does not exist, it will be created automatically.
You can pass the character encoding as the third argument. Default to utf8
.
const writeToFile = require("write-to-file");
(async () => {
const buff = Buffer.from("Hello World!");
try {
await writeToFile("foo.txt", buff.toString("hex"), "hex");
} catch(error) {
console.error(error.message);
}
})();
You can also pass an object:
writeToFile("foo.txt", buff.toString("hex"), {
encoding: "hex"
});
By default, if the file already exists, it will be overwritten. For appending data to a file, you may pass the flag
option:
const writeToFile = require("write-to-file");
(async () => {
try {
await writeToFile("foo.txt", "bar", {
flag: "a"
});
} catch(error) {
console.error(error.message);
}
})();
writeToFile(file, data, [options])
file
(String
): The file path to write to.data
(String
|Buffer
): Data to write.options
(Optional Object
|String
): You may pass the encoding as the third argument. You may also pass an object:
encoding
(String
): The character encoding to use, default to utf8
.mode
(Number
): The file permission to set, default to 0o666
.flag
(String
): The file system flag, default to w
.createDirMode
(Number
): The directory permission to set when creating the parent directory that does not exist, default to 0o777
.It returns a Promise
which when resolved contains a true
value.
MIT © Risan Bagja Pradana
FAQs
Writes data to file and automatically create its directories if not exists.
The npm package write-to-file receives a total of 16 weekly downloads. As such, write-to-file popularity was classified as not popular.
We found that write-to-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.