{"id":16644136,"url":"https://github.com/devxprite/filewrite","last_synced_at":"2025-07-01T12:39:04.762Z","repository":{"id":113715714,"uuid":"521494029","full_name":"devxprite/fileWrite","owner":"devxprite","description":"A Promise-based utility package for writing data to a file in Node.js.","archived":false,"fork":false,"pushed_at":"2022-12-25T15:35:24.000Z","size":114,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T08:31:49.104Z","etag":null,"topics":["file","filesystem","node","promise","write"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/file-write","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devxprite.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://www.buymeacoffee.com/devxprite"]}},"created_at":"2022-08-05T03:49:03.000Z","updated_at":"2024-12-23T11:44:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a7b1044e-32fd-44e3-b1f5-1aeb70ad9071","html_url":"https://github.com/devxprite/fileWrite","commit_stats":{"total_commits":20,"total_committers":2,"mean_commits":10.0,"dds":0.4,"last_synced_commit":"82d8e2b4d2730b6c7a5710fafd8d575b70eecdf9"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxprite%2FfileWrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxprite%2FfileWrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxprite%2FfileWrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxprite%2FfileWrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devxprite","download_url":"https://codeload.github.com/devxprite/fileWrite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238961327,"owners_count":19559468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file","filesystem","node","promise","write"],"created_at":"2024-10-12T08:10:32.684Z","updated_at":"2025-02-15T07:32:54.372Z","avatar_url":"https://github.com/devxprite.png","language":"JavaScript","funding_links":["https://www.buymeacoffee.com/devxprite"],"categories":[],"sub_categories":[],"readme":"# fileWrite\n\nIts a simple and flexible way to write data to a file in Node.js. It provides a number of options to customize the way data is written to the file, including the ability to overwrite or append to the file, write data synchronously or asynchronously.\n\n## Installation\n\nTo install `file-write`, run the following command in your project directory:\n\n```bash\nnpm i file-write\n```\n\n\n## Usage\n\nTo use it in EJS module, import the `fileWrite` function using the `import` syntax:\n```javascript\nimport fileWrite from 'file-write';\n\nfileWrite('path/to/file.txt', 'Test data');\n```\n\nTo use it in a CJS module, require it in your project:\n```javascript\nconst fileWrite = require('file-write');\n\nfileWrite('path/to/file.txt', 'Test data');\n```\n\n## Options\n\nThe `filewrite` function accepts the following options:\n\n### `options.encoding`\n\n**Type:** `string`\n**Default:** `utf8`\n\nThe encoding to use when writing the file. All valid [Node.js encodings](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) are supported.\n\n```javascript\nfileWrite('path/to/file.txt', 'Test data', {\n  encoding: 'utf8'\n});\n```\n\n### `options.overwrite`\n\n**Type:** `boolean`  \n**Default:** `true`\n\nIf set to `true`, the file will be overwritten with the new data. If set to `false`, the data will be appended to the file.\n\n```javascript\n// Overwrite the file with new data\nawait fileWrite('path/to/file.txt', 'Test data', {\noverwrite: true\n});\n\n// Append data to the file\nawait fileWrite('path/to/file.txt', 'Appended data', {\noverwrite: false\n});\n```\n\n\n### `options.async` \n\n**Type:** `boolean`  \n**Default:** `true`\n\nIf set to `true`, the data will be written asynchronously (return a promise). If set to `false`, the data will be written synchronously.\n\n```javascript\n// Write data to the file synchronously (blocking) return undefined\nfileWrite('path/to/file.txt', 'Test data', { async: false });\n\n// Write data to the file asynchronously (non-blocking) and return a promise\nfileWrite('path/to/file.txt', 'Test data', { async: true }).then(() =\u003e {\n  console.log('File written successfully!');\n}).catch((err) =\u003e {\n  console.error(err);\n});\n```\n\n\n### `options.newLine`\n\n**Type:** `boolean`  \n**Default:** `true`\n\nIt Ensure that contents has a trailing newline before writing it to the file.\n\n\n### `options.increment` \n\n**Type:** `boolean`  \n**Default:** `false`\n\nIf set to `true` and the file already exists, the file will be renamed to include a number in parentheses after the file name. For example, if the file is named `foo.txt` and `increment` is `true`, the file will be renamed to `foo (2).txt`.\n\n```javascript\n// Increment the file name if the file already exists\nawait fileWrite('path/to/file.txt', 'Test data', {\nincrement: true\n});\n```\n\n\n### `options.exclusive` \n\n**Type:** `boolean`  \n**Default:** `false`\n\nIf set to `true`, the promise will be rejected with an error if the file already exists. If set to `false`, the file will be overwritten or appended to depending on the value of the `overwrite` option.\n\n```javascript\n// Reject the promise with an error if the file already exists\nawait fileWrite('path/to/file.txt', 'Test data', {\nexclusive: true\n});\n```\n\n## License\n\nThe `filewrite` library is released under the MIT license. See [LICENSE](LICENSE) for more details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxprite%2Ffilewrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevxprite%2Ffilewrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxprite%2Ffilewrite/lists"}