Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pkg

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pkg

Package your Node.js project into an executable

  • 5.8.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
191K
decreased by-4.96%
Maintainers
1
Weekly downloads
 
Created

What is pkg?

The 'pkg' npm package is used to package Node.js projects into executable files for various platforms, including Windows, macOS, and Linux. This allows developers to distribute their applications without requiring users to have Node.js installed.

What are pkg's main functionalities?

Packaging a Node.js project

This feature allows you to package your Node.js project into an executable file. The code sample demonstrates how to use the 'pkg' command to package the current directory ('.') into an executable.

const { exec } = require('child_process');
exec('pkg .', (error, stdout, stderr) => {
  if (error) {
    console.error(`Error: ${error.message}`);
    return;
  }
  if (stderr) {
    console.error(`Stderr: ${stderr}`);
    return;
  }
  console.log(`Stdout: ${stdout}`);
});

Specifying target platforms

This feature allows you to specify the target platforms for the executable. The code sample demonstrates how to package the project for Windows, macOS, and Linux using Node.js version 14.

const { exec } = require('child_process');
exec('pkg . --targets node14-win-x64,node14-mac-x64,node14-linux-x64', (error, stdout, stderr) => {
  if (error) {
    console.error(`Error: ${error.message}`);
    return;
  }
  if (stderr) {
    console.error(`Stderr: ${stderr}`);
    return;
  }
  console.log(`Stdout: ${stdout}`);
});

Including additional files

This feature allows you to include additional files in the packaged executable. The code sample demonstrates how to include all files in the 'assets' directory.

const { exec } = require('child_process');
exec('pkg . --include assets/**/*', (error, stdout, stderr) => {
  if (error) {
    console.error(`Error: ${error.message}`);
    return;
  }
  if (stderr) {
    console.error(`Stderr: ${stderr}`);
    return;
  }
  console.log(`Stdout: ${stdout}`);
});

Other packages similar to pkg

FAQs

Package last updated on 08 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc