0

I want to make a node .exe file that runs in the background.

I'm not using third npm packages, but the server is using these modules:

  • FS (File System)
  • Exec (Child Process)
  • HTTP (Server)

The Exec triggers a batch file that opens a console.exe program.

Is there a way to bundle this up into a single .exe?

1

2 Answers 2

1

There is an npm package called pkg. You can install it with

npm i pkg -g 

Then you can convert your node project into an exe (macos and linux too) using:

pkg (yourfile).js 

You can put the batch file with your packaged node exe to run it.

EDIT:

I misunderstood the question before, but to do this, you need to use a generator file. Unfourtunately it wont work for your binary files, but if you want use text files, you can do something like:

Create a file structure like this:

src/ generator/ generate.js asset.txt app.js makefile 

in your makefile, put

.PHONY: all all: node generator/generate.js pkg app.js 

and in generate.js you can have something like:

fs.readFile("asset.txt", (e, data) => { fs.writeFile("assets.js", ` var asset_txt = \`${data}\` `); }); 

and in your app.js, require the assets.js file. It may be a messy solution, but I don't think there is a really good way.

Sign up to request clarification or add additional context in comments.

1 Comment

I try this one, but the assets are not included, I had to put the .exe file next to the rest of the files.
0

You can check this package: Nexe

1 Comment

You can read this tutorial too: dev.to/jochemstoel/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.