Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

filendir

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filendir

Filendir allows you to write a file and create the directories found in its path if needed.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Filendir

Write a file given a full path. Create the missing directories if necessary.


js-standard-style Build Status Node.js >= 10

API

Filendir exposes an asynchronous and a synchronous write method.

It also exposes mkdirp to create directories only, if you need it.

filendir versions node support

  • 1.x for nodejs v4 to v9
  • 2.x for nodejs v10 to now

Synchronous write

  • filendir.ws (shorthand)
  • filendir.writeFileSync

Apart from creating the missing directories, it has the same behaviour and interface than node fs.writeFileSync.

// signature
filendir.writeFileSync(filename, data[, options])

See fs.writeFileSync in Node.js site

Example

var path = require('path')
var filendir = require('filendir')
var filename = path.join('let', 's', 'nest', 'some', 'directories', 'myfile.txt')
var content = 'Hello World'

filendir.ws(filename, content)

Asynchronous write

  • filendir.wa (shorthand)
  • filendir.writeFile

Apart from creating the missing directories, it has the same behaviour and interface than node fs.writeFile.

Extra from fs.writefile: you can use promises

// callback use
filendir.writeFile(filename, data[, options], callback)
// with promise
await filendir.writeFile(filename, data[, options])

See fs.writeFile in Node.js site

Example

var path = require('path')
var filendir = require('filendir')
var filename = path.join('let', 's', 'nest', 'some', 'directories', 'myfile.txt')
var content = 'Hello World'

filendir.wa(filename, content, function (err) {
  if (!err) {
    console.log('File written!')
  }
})

filendir.mkdirp

Credits to Substack. Would have been harder to do this without it.

See https://www.npmjs.org/package/mkdirp

Keywords

FAQs

Package last updated on 29 Apr 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc