If you’ve built an application using Node.JS, and compiled it to a Windows binary with PKG, you will have noticed that the file description, copyright, and icon match those of the Node.JS runtime. Updating the file properties with Resource Hacker sometimes works, however, updating the icon may corrupt the application, so that it will no longer run.
Follow along and we will show you how to update the properties of a Windows .exe that has been built as Node.JS code compiled with PKG.
Set the PKG_CACHE_PATH environment variable
export PKG_CACHE_PATH=./cacheFolder
Download the Node.js Binary
pkg .
Rename the modified binary (cacheFolder/v3.4/fetched-v18.5.0-win-x64) to replace fetched with built. For example: built–v18.5.0-win-x64 so that pkg recognizes it as custom-built.
Install rcedit
npm install rcedit
Create a modbinary.js:
const rcedit = require("rcedit");
const path = require("path");
async function modifyBinary() {
const binaryPath = path.join(
__dirname,
"cacheFolder/v3.4/built-v18.5.0-win-x64"
);
await rcedit(binaryPath, {
icon: "C:\\icon.ico",
"version-string": {
FileDescription: "My cool app",
ProductName: "myApp",
LegalCopyright: "Copyright My Company. All Rights Reserved.",
OriginalFilename: "myApp.exe",
CompanyName: "My Company",
InternalName: "My Company",
FileVersion: "1.0.0",
ProductVersion: "1.0.0",
},
"file-version": "1.0.0",
"product-version": "1.0.0",
});
}
modifyBinary()
.then(() => console.log("Binary modified successfully!"))
.catch((err) => console.error("Error modifying binary:", err));
Be sure to replace the binaryPath with the correct file location (cacheFolder/v3.4/fetched-v18.5.0-win-x64, but will be different versions depending on Node.JS). Notice the additional escape backslash when specifying the icon file location on Windows. Update this location to the correct path of your icon file.
Run the script
node ./binmod.js
Build Your Executable Using pkg
pkg --target node18-win-x64 --output yourAppName .