Skip to content

A promise based simplified Node.js directory copy recursive API

License

Notifications You must be signed in to change notification settings

mazik/fs-easy-dir-copy

Repository files navigation

FS Easy Dir Copy

A promise based simplified Node.js directory copy recursive API that also returns the list of files and directories.

Build Status Total Downloads License


Why anohter Node.js FS package for copying directories?

There are so many great packages out there based on the Node.js file system. However, recently I felt that there's nothing very simple but offers asyncrhonus operation in Node.js file system for copying directories.

In addition, I have always wanted to publish packages in NPM. This package just let me starts my journey with NPM and GitHub package registry. I also learned a lot on how the GitHub Actions works.

Installation

This package is currently available on both NPM and GitHub package registry. You can either install it from NPM or GitHub package registry like the followings:

Install from the command line:

npm install @mazik/fs-easy-dir-copy@latest

Getting started

The package @mazik/fs-easy-dir-copy() accepts two arguments. The first argument is a string of source path and the second argument is also a string of destination path.

You will need to import the package as you'd normally do with any other NPM package like the following:

const copyDirectory = require('@mazik/fs-easy-dir-copy')

You'll need to use the copyDirectory using asynchronously:

const copyDirectory = require('@mazik/fs-easy-dir-copy');

copyDirectory('./sourcePath', './destinationPath').then(items => {
    console.log(items);
}).catch(error => {
    console.log(error);
})

Based on your source path, the items variable will return an array of objects like the following:

[
  { name: 'another', directory: true },
  { name: 'readme.md', directory: false },
  { name: 'test.md', directory: false },
]

Requirements

  • "node": ">=13.11.0"

Running the tests

You'll need to simply run the following:

yarn test

License

This project is licensed under the MIT License - see the LICENSE file for details