Skip to content
Fetch a npm package's source code
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE.md
README.md
example.js
index.js
package-lock.json
package.json

README.md

fetch-package-source

Fetch the source code of a particular version of a package published to npm.

This does not download from npm as not all files might be published there. Therefore the source might be more useful to you, for example if you want to run its test suite.

Usage

const fetchPackageSource = require('fetch-package-source')
const { tmpdir } = require('os')

const dir = `${tmpdir()}/${Date.now()}`
await fetchPackageSource(
  'https://github.com/juliangruber/browser-run',
  '1.0.0',
  dir
)
console.log(dir)
$ node example.js
/var/folders/h2/vg0v3hgn26x5gb4w64yx59zh0000gn/T/1577899257798

$ ls /var/folders/h2/vg0v3hgn26x5gb4w64yx59zh0000gn/T/1577899257798
README.md	example.js	index.js	package.json	test

Sponsors

This project is sponsored by CTO.ai, making it easy for development teams to create and share workflow automations without leaving the command line.

You can’t perform that action at this time.