Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/namshi/node-file-ensure
Ensures that a file exists: if not, it creates it.
https://github.com/namshi/node-file-ensure
Last synced: 1 day ago
JSON representation
Ensures that a file exists: if not, it creates it.
- Host: GitHub
- URL: https://github.com/namshi/node-file-ensure
- Owner: namshi
- Created: 2014-08-22T11:58:00.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-08-27T07:56:57.000Z (about 10 years ago)
- Last Synced: 2024-10-31T17:19:20.370Z (7 days ago)
- Language: JavaScript
- Size: 194 KB
- Stars: 1
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## file-ensure
[![Build Status](https://travis-ci.org/namshi/node-file-ensure.svg?branch=master)](https://travis-ci.org/namshi/node-file-ensure)
Simply ensure that a file exists, else create it: this becomes handy
when you provide skeleton file, like `config_dev.yml.example` that should
be ignored in git but need to be available in your FS to run your
application.## Installation
As usual, this module is provided through
[NPM](https://www.npmjs.org/package/file-ensure):```
npm install file-ensure
```## Usage
The module's usage is straightforward:
```
ensure(filePath, options, [callback])# or
ensure(filePath, [callback])
```Simply require and use it for every file
you want to make sure that exists in
your filesystem:``` javascript
var ensure = require('file-ensure');ensure('path/to/config_dev.yml');
```Simple as that :)
You can also create the file from another file:
``` javascript
ensure('path/to/config_dev.yml', {from: 'path/to/config_dev.yml.example'}, function(err){
console.log(fs.readFileSync('path/to/config_dev.yml').toString() === fs.readFileSync('path/to/config_dev.yml.example').toString());
});
```## Tests
This small library is tested through mocha, while
automated tests run on [travis](https://travis-ci.org/namshi/node-file-ensure).