Skip to content

SlimIO/Nodejs-downloader

Repository files navigation

nodejs-downloader

version Maintenance mit dep size Known Vulnerabilities Build Status

Node.js binary and headers downloader. This package allow us to programmatically exploit the following Node.js Release API: https://nodejs.org/download/release.

Requirements

Getting Started

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

$ npm i @slimio/nodejs-downloader
# or
$ yarn add @slimio/nodejs-downloader

Usage example

const { join } = require("path");
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);

API

getNodeRelease(version: String): Release

Retrieve information about a given Node.js release.

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:

{ 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 }
downloadNodeFile(file?: String, options?: DownloadOptions): String

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().
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);
extract(file: String): String

Extract .tar.gz and .zip file. This method help you to extract Node.js files !

Following the downloadNodeFile example:

const tarFile = await downloadNodeFile(File.Headers, {
    version: "v11.0.0",
    dest: "./headers"
});
const dirName = await extract(tarFile);
console.log(dirName);

Files

File CONSTANT is described by the following interface

interface NodeFile {
    Headers: "-headers.tar.gz",
    AixPPC64: "-aix-ppc64.tar.gz",
    Darwin64: "-darwin-x64.tar.gz",
    Arm64: "-linux-arm64.tar.gz",
    Armv6l: "-linux-armv6l.tar.gz",
    Armv7l: "-linux-armv7l.tar.gz",
    PPC64le: "-linux-ppc64le.tar.gz",
    S390x: "-linux-s390x.tar.gz",
    Linux64: "-linux-x64.tar.gz",
    SunOS64: "-sunos-x64.tar.gz",
    WinBinary64: "-win-x64.zip",
    WinBinary86: "-win-x86.zip",
    WinExe64: "-x64.msi",
    WinExe86: "-x86.msi"
}

Dependencies

This project is covered by the SlimIO security policy and undergoes regular security audits.

Name Refactoring Security Risk Usage
tar-fs ⚠️ Major ⚠️ high Used to extract tar.gz archive in extract() method.
@slimio/unzipper ⚠️ Major ⚠️ high Modern yauzl wrapper used to unzip .zip archive in extract() method.

License

MIT

About

SlimIO - Node.js binary and headers downloader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •