Bundle and Deploy my nodejs program as an executable
Asked Answered
R

1

9

I have a program written with node js that I want to bundle and distribute as "stand-alone" executable program.

I want to run the program through cmd only with the the executable file name (without using npm run start or node file.js). i.e. my_program arguments.

What is the most recommended way to achieve this?

Thanks.

Romaineromains answered 19/6, 2020 at 17:27 Comment(0)
B
15

There are several options you can choose from. I would recommend checking out Pkg.

With Pkg, you can package your node application into a single executable for Windows, Linux or Mac.

Simply install Pkg globally on your machine by running the command:

npm install -g pkg

and then add your point of entry to the package.json file as shown below:

{
   "bin": "bin.js" // or whatever your point of entry is
}

Afterwards, from your app directory simply run the command

pkg .

This would build the executables for Windows, Linux and MacOS.

You can execute the executable by running:

Windows: your_exec-win.exe # windows

Linux: chmod u+x your_exec-linux; ./your_exec-linux

Barris answered 19/6, 2020 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.