Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/axelpale/node-fsensure
Ensure directories and files exists or are removed in Node.js.
https://github.com/axelpale/node-fsensure
Last synced: about 1 month ago
JSON representation
Ensure directories and files exists or are removed in Node.js.
- Host: GitHub
- URL: https://github.com/axelpale/node-fsensure
- Owner: axelpale
- License: mit
- Created: 2013-10-20T14:37:18.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-10-31T21:43:02.000Z (about 11 years ago)
- Last Synced: 2024-04-26T21:45:14.141Z (8 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fsensure
Ensure directories and files exists or are removed in Node.js.
## Install
Using [npm](http://npmjs.org):
```
npm install fsensure
```##Examples
Create directories recursively like `mkdir -p`:
```js
var fsensure = require('fsensure');fsensure.dir.exists('/tmp/foo/bar/baz', function (err) {
if (err) { console.error(err); return; }
console.log('/tmp/foo/bar/baz now exists');
});
```Move files around and automatically create the required directories:
```js
var fsensure = require('fsensure');fsensure.file.move('/tmp/info.txt', '/tmp/archive/info.md', function (err) {
if (err) { console.error(err); return; }
console.log('/tmp/info.txt moved to /tmp/archive/info.md');
});
```## Methods
### dir.exists(path, \[mode\], callback)
Ensure that directory exists. If directory does not exist, try to create the directory in path. Understand the path as a path to directory.
### dir.existsSync(path, \[mode\])
Sync version of fsensure.dir.exists.
### file.move(source, target, callback)
Alias of fsensure.file.rename.
### file.rename(source, target, callback)
First ensures that the directories of the target filepath exists, creates the directories then renames the file.
### file.dir.exists(filepath, callback)
Ensures that the directories of filepath exist. Difference to dir.exists is that here filepath is understood as path to a non-directory file.
### file.copy(source, target, callback)
Ensure that target path exists and copy the file.
### file.remove(target, callback)
Alias of fsensure.file.unlink
### file.unlink(target, callback)
Ensure that target file is removed. Remove the file if possible.
## TODO
- more tests
- more comprehensive documentation
- file.dir.existsSync