0.0.1 • Published 3 years ago
external-binary v0.0.1
External Binary
Quite often we want to make use of an external program in node.js scripts. Such as MongoDB, Nginx etc. This package helps manage the lifecycle of such operation.
Author
Usage
To install:
yarn add external-binary
import { ExternalProgram } from "external-binary"
import { spawn } from "child_process"
;(async () => {
const program = new ExternalProgram({
name: `mongo`,
sources: [
{
arch: "x64",
platform: "linux",
downloadUrl: `https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1804-4.2.8.tgz`,
checksum: "123456",
checksumAlgorithm: "md5",
decompress: true, // if the downloaded file needs to be decompressed. the format is retrieved by extension. otherwise assume the file is the executable
binaryPath: `bin/mongo` // if decompressed, the relative path to the binary starting from the decompressed folder
}
]
})
await program.load() // prepare the binary. e.g. download/unzip
const process = spawn(program.executablePath, ["--port", "27017"])
process.on("data", data => console.log(data))
process.on("exit", code => console.log(`exited ${code}`))
process.kill()
})()