write-file

Writing a file to disk, creates intermediate directories in the destination path if they dont already exist.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
write-file
1.0.08 years ago8 years agoMinified + gzip package size for write-file in KB

Readme

Writing a file to disk, creates intermediate directories in the destination path if they dont already exist.

!code climatecodeclimate-imgcodeclimate-url !standard code stylestandard-imgstandard-url !travis build statustravis-imgtravis-url !coverage statuscoveralls-imgcoveralls-url !dependency statusdavid-imgdavid-url

Install

Install with npm

$ npm i write-file --save

Usage

For more use-cases see the tests

const writeFile = require('write-file')

API

writeFile

Writes a file to disk with support for creating intermediate directories and JSON files.

Params
  • <fp> {String|Buffer|Number}: filepath to the new file
    data {String|Buffer|Object}: if object, JSON.stringify and writes it
    [options] {Object|String}: passed to mkdirp too; if string, treats it as opts.encoding
    callback {Function}: done callback

Example
var writeFile = require('write-file')

writeFile('foo/bar/baz/qux.txt', 'some contents', function (err) {
  if (err) return console.log(err)
  console.log('file is written')
})

// automatically writes a json files
writeFile('foo/qux/bar.json', { foo: 'bar' }, function (err) {
  // if not `err`, file is written
})

Related

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent !new message to charlikenew-message-imgnew-message-url !freenode #charlikefreenode-imgfreenode-url

!tunnckoCore.tkauthor-www-imgauthor-www-url !keybase tunnckoCorekeybase-imgkeybase-url !tunnckoCore npmauthor-npm-imgauthor-npm-url !tunnckoCore twitterauthor-twitter-imgauthor-twitter-url !tunnckoCore githubauthor-github-imgauthor-github-url