11cb0ef41Sopenharmony_ci# libnpmpack 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci[](https://npm.im/libnpmpack) 41cb0ef41Sopenharmony_ci[](https://npm.im/libnpmpack) 51cb0ef41Sopenharmony_ci[](https://github.com/npm/cli/actions/workflows/ci-libnpmpack.yml) 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci[`libnpmpack`](https://github.com/npm/libnpmpack) is a Node.js library for 81cb0ef41Sopenharmony_ciprogrammatically packing tarballs from a local directory or from a registry or github spec. If packing from a local source, `libnpmpack` will also run the `prepack` and `postpack` lifecycles. 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci## Table of Contents 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci* [Example](#example) 131cb0ef41Sopenharmony_ci* [Install](#install) 141cb0ef41Sopenharmony_ci* [API](#api) 151cb0ef41Sopenharmony_ci * [`pack()`](#pack) 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci## Example 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci```js 201cb0ef41Sopenharmony_ciconst pack = require('libnpmpack') 211cb0ef41Sopenharmony_ci``` 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci## Install 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci`$ npm install libnpmpack` 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci### API 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci#### <a name="pack"></a> `> pack(spec, [opts]) -> Promise` 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciPacks a tarball from a local directory or from a registry or github spec and returns a Promise that resolves to the tarball data Buffer, with from, resolved, and integrity fields attached. 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ciIf no options are passed, the tarball file will be saved on the same directory from which `pack` was called in. 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci`libnpmpack` uses [`pacote`](https://npm.im/pacote). 361cb0ef41Sopenharmony_ciMost options are passed through directly to that library, so please refer to 371cb0ef41Sopenharmony_ci[its own `opts` 381cb0ef41Sopenharmony_cidocumentation](https://www.npmjs.com/package/pacote#options) 391cb0ef41Sopenharmony_cifor options that can be passed in. 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci##### Examples 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci```javascript 441cb0ef41Sopenharmony_ci// packs from cwd 451cb0ef41Sopenharmony_ciconst tarball = await pack() 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ci// packs from a local directory 481cb0ef41Sopenharmony_ciconst localTar = await pack('/Users/claudiahdz/projects/my-cool-pkg') 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci// packs from a registry spec 511cb0ef41Sopenharmony_ciconst registryTar = await pack('abbrev@1.0.3') 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci// packs from a github spec 541cb0ef41Sopenharmony_ciconst githubTar = await pack('isaacs/rimraf#PR-192') 551cb0ef41Sopenharmony_ci``` 56