@slimio/nodejs-downloader
Version:
Node.js binary and headers downloader
151 lines (122 loc) • 4.23 kB
Markdown

[](https://github.com/SlimIO/nodejs-downloader/commit-activity)
[](https://github.com/SlimIO/nodejs-downloader/blob/master/LICENSE)

[](https://snyk.io/test/github/SlimIO/nodejs-downloader?targetFile=package.json)
[](https://travis-ci.com/SlimIO/Nodejs-downloader) [](https://greenkeeper.io/)
Node.js binary and headers downloader
This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
```bash
$ npm i @slimio/nodejs-downloader
$ yarn add @slimio/nodejs-downloader
```
```js
const {
getNodeRelease,
downloadNodeFile,
extract,
constants: { File }
} = require("@slimio/nodejs-downloader");
// CONSTANTS
const DOWNLOAD = join(__dirname, "download");
async function main() {
const nodeRelease = await getNodeRelease("v8.0.0");
console.log(nodeRelease);
// Download Node.js headers (of current Node.js version).
const tarFile = await downloadNodeFile(File.Headers, {
dest: DOWNLOAD
});
// Extract tar.gz
const dirHeaders = await extract(tarFile);
console.log(dirHeaders);
}
main().catch(console.error);
```
<details><summary>getNodeRelease(version: String): Release</summary
<br />
Retrieve information about a given Node.js release.
```js
const { getNodeRelease } = require("@slimio/nodejs-downloader");
async function main() {
const release = await getNodeRelease("v8.0.0");
console.log(release);
}
main().catch(console.error);
```
Stdout will look like this:
```bash
{ name: "N/A",
version: 'v8.0.0',
date: 2017-05-30T00:00:00.000Z,
files:
Set {
'aix-ppc64',
'headers',
'linux-arm64',
'linux-armv6l',
'linux-armv7l',
'linux-ppc64le',
'linux-s390x',
'linux-x64',
'linux-x86',
'osx-x64-pkg',
'osx-x64-tar',
'src',
'sunos-x64',
'sunos-x86',
'win-x64-7z',
'win-x64-exe',
'win-x64-msi',
'win-x64-zip',
'win-x86-7z',
'win-x86-exe',
'win-x86-msi',
'win-x86-zip' },
npm: '5.0.0',
v8: '5.8.283.41',
uv: '1.11.0',
zlib: '1.2.11',
openssl: '1.0.2k',
modules: 57,
lts: false }
```
</details>
<details><summary>downloadNodeFile(file?: String, options?: DownloadOptions): String</summary
<br />
Download a given release Node.js file... Use the constant `File` of the module to known all available Node.js files !
- Default value for `version` is the result of `process.version`.
- Default value for `dest` is the result of `process.cwd()`.
```js
const { downloadNodeFile, constants: { File } } = require("@slimio/nodejs-downloader");
async function main() {
const tarFile = await downloadNodeFile(File.Headers, {
version: "v11.0.0",
dest: "./headers"
});
console.log(tarFile);
}
main().catch(console.error);
```
</details>
<details><summary>extract(file: String): String</summary
<br />
Extract `.tar.gz` and `.zip` file. This method help you to extract Node.js files !
Following the downloadNodeFile example:
```js
const tarFile = await downloadNodeFile(File.Headers, {
version: "v11.0.0",
dest: "./headers"
});
const dirName = await extract(tarFile);
console.log(dirName);
```
</details>
- Complete the file list (not all files are supported).
## License
MIT