Web Front-end
JS Tutorial
Let's talk about how to use pkg to package Node.js projects into executable files.
Let's talk about how to use pkg to package Node.js projects into executable files.
How to package nodejs executable file with pkg? The following article will introduce to you how to use pkg to package the Node project into an executable file. I hope it will be helpful to you!

Using pkg, you can package your Node.js project into an executable file that can even be run on devices where Node.js is not installed. [Related tutorial recommendations: nodejs video tutorial]
Experimental environment
Operating system: windows
node version: 16.14.2
##Operation process
- Download PKG
$ npm install -g pkg
- Packaging program
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(3000, () => {
console.log('Express web app on localhost:3000');
});$ pkg server.js
First time Error
At this time, an error will be reported$ pkg server.js
> pkg@5.6.0
> Targets not specified. Assuming:
node16-linux-x64, node16-macos-x64, node16-win-x64
> Fetching base Node.js binaries to PKG_CACHE_PATH
fetched-v16.14.2-linux-x64 [ ] 0%> Not found in remote cache:
{"tag":"v3.3","name":"node-v16.14.2-linux-x64"}
> Building base binary from source:
built-v16.14.2-linux-x64
> Error! Not able to build for 'linux' here, only for 'win'$ pkg -t win server.js
Second error report
An error message was reported again during compilation:$ pkg -t win server.js
> pkg@5.6.0
> Fetching base Node.js binaries to PKG_CACHE_PATH
fetched-v16.14.2-win-x64 [ ] 0%> Not found in remote cache:
{"tag":"v3.3","name":"node-v16.14.2-win-x64"}
> Building base binary from source:
built-v16.14.2-win-x64
> Fetching Node.js source archive from nodejs.org...
> Error! AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:official website to download the corresponding version file. For example, mine is node-v16.14.2-win-x64
Official website address: https://github.com /vercel/pkg-fetch/releases
C:\Users\MangoDowner.pkg-cache. After splicing the fetch tag, it becomes the final directory. Refer to the information in the error report to get The tag is v3.3
{"tag":"v3.3","name":"node-v16.14.2-win-x64"}So the final file address is C:\Users\MangoDowner .pkg-cache\v3.3\fetched-v16.14.2-win-x64
$ pkg -t win server.js > pkg@5.6.0
nodejs tutorial!
The above is the detailed content of Let's talk about how to use pkg to package Node.js projects into executable files.. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undresser.AI Undress
AI-powered app for creating realistic nude photos
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undress AI Tool
Undress images for free
Clothoff.io
AI clothes remover
AI Hentai Generator
Generate AI Hentai for free.
Hot Article
Hot Tools
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
1386
52
An article about memory control in Node
Apr 26, 2023 pm 05:37 PM
The Node service built based on non-blocking and event-driven has the advantage of low memory consumption and is very suitable for handling massive network requests. Under the premise of massive requests, issues related to "memory control" need to be considered. 1. V8’s garbage collection mechanism and memory limitations Js is controlled by the garbage collection machine
Detailed graphic explanation of the memory and GC of the Node V8 engine
Mar 29, 2023 pm 06:02 PM
This article will give you an in-depth understanding of the memory and garbage collector (GC) of the NodeJS V8 engine. I hope it will be helpful to you!
How to use express to handle file upload in node project
Mar 28, 2023 pm 07:28 PM
How to handle file upload? The following article will introduce to you how to use express to handle file uploads in the node project. I hope it will be helpful to you!
Let's talk in depth about the File module in Node
Apr 24, 2023 pm 05:49 PM
The file module is an encapsulation of underlying file operations, such as file reading/writing/opening/closing/delete adding, etc. The biggest feature of the file module is that all methods provide two versions of **synchronous** and **asynchronous**, with Methods with the sync suffix are all synchronization methods, and those without are all heterogeneous methods.
An in-depth analysis of Node's process management tool 'pm2”
Apr 03, 2023 pm 06:02 PM
This article will share with you Node's process management tool "pm2", and talk about why pm2 is needed, how to install and use pm2, I hope it will be helpful to everyone!
Pi Node Teaching: What is a Pi Node? How to install and set up Pi Node?
Mar 05, 2025 pm 05:57 PM
Detailed explanation and installation guide for PiNetwork nodes This article will introduce the PiNetwork ecosystem in detail - Pi nodes, a key role in the PiNetwork ecosystem, and provide complete steps for installation and configuration. After the launch of the PiNetwork blockchain test network, Pi nodes have become an important part of many pioneers actively participating in the testing, preparing for the upcoming main network release. If you don’t know PiNetwork yet, please refer to what is Picoin? What is the price for listing? Pi usage, mining and security analysis. What is PiNetwork? The PiNetwork project started in 2019 and owns its exclusive cryptocurrency Pi Coin. The project aims to create a one that everyone can participate
Let's talk about the event loop in Node
Apr 11, 2023 pm 07:08 PM
The event loop is a fundamental part of Node.js and enables asynchronous programming by ensuring that the main thread is not blocked. Understanding the event loop is crucial to building efficient applications. The following article will give you an in-depth understanding of the event loop in Node. I hope it will be helpful to you!
What should I do if node cannot use npm command?
Feb 08, 2023 am 10:09 AM
The reason why node cannot use the npm command is because the environment variables are not configured correctly. The solution is: 1. Open "System Properties"; 2. Find "Environment Variables" -> "System Variables", and then edit the environment variables; 3. Find the location of nodejs folder; 4. Click "OK".


