# copy-node-modules

> Fast Node.js modules deployment to destination directory

Latest version **1.1.1** (published 2018-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install copy-node-modules
pnpm add copy-node-modules
yarn add copy-node-modules
bun add copy-node-modules
```

Provides the command `copy-node-modules`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-12-09 |
| First published | 2016-05-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 9 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Arlo Liu |
| Maintainers | arlo |
| Keywords | install, deployment, package |

## Links

- npm: https://www.npmjs.com/package/copy-node-modules
- Repository: https://github.com/arloliu/copy-node-modules
- Homepage: https://github.com/arloliu/copy-node-modules#readme
- Issues: https://github.com/arloliu/copy-node-modules/issues
- npm.io page: https://npm.io/package/copy-node-modules

## Dependencies (9)

- [ncp](https://npm.io/package/ncp.md) ^2.0.0
- [async](https://npm.io/package/async.md) ^2.6.1
- [yargs](https://npm.io/package/yargs.md) ^12.0.5
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [semver](https://npm.io/package/semver.md) ^5.6.0
- [jsonfile](https://npm.io/package/jsonfile.md) ^5.0.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.15
- [lodash.flatten](https://npm.io/package/lodash.flatten.md) ^4.4.0
- [lodash.uniqwith](https://npm.io/package/lodash.uniqwith.md) ^4.5.0

## Recent versions

- 1.1.1 (latest) — 2018-12-09
- 1.1.0 — 2018-12-04
- 1.0.8 — 2018-09-15
- 1.0.7 — 2018-08-15
- 1.0.6 — 2018-06-15
- 1.0.5 — 2018-06-06
- 1.0.4 — 2018-03-16
- 1.0.3 — 2017-12-07
- 1.0.2 — 2017-04-23
- 1.0.1 — 2017-03-17
- 1.0.0 — 2017-03-17
- 0.4.1 — 2016-05-12
- 0.3.1 — 2016-05-11

## README

# copy-node-modules - fast Node.js modules deployment to destination directory

[![NPM version](https://img.shields.io/npm/v/copy-node-modules.svg)](https://www.npmjs.com/package/copy-node-modules)
[![Downloads/month](https://img.shields.io/npm/dm/copy-node-modules.svg)](https://www.npmjs.com/package/copy-node-modules)

Copy all modules listed in `dependencies` or/and `devDependencies` field of `package.json` to destination directory. 

The procedure:

1. Read `package.json` from source directory and read `dependencies` or `devDependencies` field.
2. Search for existing modules and ther dependencies in source directory.
3. Copy all modules to destination directory.

Modern applications use lots of modules, each module depends on more modules resulting in hundreds of modules being installed when typing `npm install`. This module will help you to save time from slow `npm install` when you want to pack/deploy your application to a directory which contains all needed modules. 

It will save you a bunch of time to deploy a stand-alone application from existing development directory, no need to fetch all modules from remote repository.

## Installation

```bash
yarn add copy-node-modules --dev
```

or

```bash
npm install copy-node-modules --save-dev
```

## Programmatic Usage

ES6+ environment:

```javascript
const copyNodeModules = require('copy-node-modules');
```

ES6+ environment with `import` support:

```javascript
import copyNodeModules from 'copy-node-modules'; 
```

ES5

```javascript
var copyNodeModules = require('copy-node-modules');
```

### copyNodeModules(srcDir, dstDir, [options], callback)

* `srcDir`: source directory containing `package.json` file.
* `dstDir`: destination directory to copy modules to (modules will be copied to `dstDir/node_modules` directory).
* `options`:

  - `devDependencies`: boolean value, defaults to **false**, showing whether modules in `devDependencies` field of `package.json` should also be copied (when it's set to **true**).
  - `concurrency`: integer value, max number of root packages whose files are being copied concurrently.
  - `filter`: `RegExp` or function that accepts one value (the full path) and returns a boolean (copy on true).
  
* `callback(err, results)`: A callback which is called when all copy tasks have finished or error occurs, `results` is an array contains copied modules, each item is an object as `{name: 'xxx', version: 'xxx'}`

## Examples

```javascript
const copyNodeModules = require('copy-node-modules');
const srcDir = '/somewhere/project';
const dstDir = '/somewhere/project/dist';
copyNodeModules(srcDir, dstDir, { devDependencies: false }, (err, results) => {
  if (err) {
    console.error(err);
    return;
  }
  Object.keys(results).forEach(name => {
    const version = results[name];
    console.log(`Package name: ${name}, version: ${version}`);
  });
});
```

### Example with a filter method

```javascript
const copyNodeModules = require('copy-node-modules');
const srcDir = '/somewhere/project';
const dstDir = '/somewhere/project/dist';

// Filter method that will ignore node_module folders in a node module
const filter = path => {
  const firstIndex = path.indexOf('node_modules');
  return v.indexOf('node_modules', firstIndex + 1) === -1;
}

copyNodeModules(srcDir, dstDir, { devDependencies: false, filter }, (err, results) => {
  if (err) {
    console.error(err);
    return;
  }
  Object.keys(results).forEach(name => {
      const version = results[name];
      console.log(`Package name: ${name}, version: ${version}`);
    });
});
```

## CLI Usage

```
copy-node-modules src_dir dest_dir [-d|--dev] [-c|--concurrency] [-v|--verbose] [-f|--filter]
```

* `src_dir`: source directory containing `package.json` file.
* `dest_dir`: destination directory to copy modules to (modules will be copied to `dest_dir/node_modules` directory).
* `-d|--dev`: whether modules in `devDependencies` field of `package.json` should be also copied.
* `-c|--concurrency`: max number of root packages whose files are being copied concurrently.
* `-v|--verbose`: verbose mode.
* `-f|--filter`: regular Expression, files that match this expression will be copied; it also matches directories fi:
    -f `index.html` matches `path/index.html` but not `path/` and because of this `index.html` is not copied.

## License

MIT

---
_Source: https://npm.io/package/copy-node-modules · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
