The pkg command is helps to interface enables you to package your Node.js project into an executable and able to execute the application on our machine without Node.js installed. Lets discuss convert the build code convert to binaries.
Before to do that, have to Install the Node.js server and dependencies in your machine using the command below,
$ sudo apt-get install curl python-software-properties
$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Once installed the Node.js server in your machine, make sure that the latest version by the command,
$ node -v
Install the npm package by the command,
$ apt-get install npm
pkg package is required for convert js files to single binary file format, so install the pkg globally using the npm command,
$ npm install -g pkg
Next, build the application by npm install,
npm install
Now, convert files to the Binarly format using pkg command which has installed in your machine already,
pkg server.js --targets node8-linux-x64
or
/usr/local/bin/pkg .
That's it.
Comments (0)