# Can I package whole nodered project using pkg node?

**URL:** https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271
**Category:** General
**Created:** [7 January 2022 22:08 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271 "2022-01-07T22:08:04Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [7 January 2022 22:08 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/1 "2022-01-07T22:08:04Z")

</div>

Hi nodered experts,

I successfully created a project on nodered using an offline installer by TotallyInformation. It means I can run nodered projects independently.

Now I want those "nodereds" to run on a single executable file (each nodered project have their own .exe file) without installing node.js on a the target computer.

I found this node-pkg

> **[pkg](https://www.npmjs.com/package/pkg)**
>
> Package your Node.js project into an executable

But I am not just sure how am I going to implement this in my nodered project folder.

I want to retain all my user interface to be in the browser when I run the executable file created using that pkg.

The purpose of building in in one package is.

1. So that the user cannot edit the code in nodered
2. No need to install the nodejs in the target computer.

Thank you very much.

Regards,  
Henjoe

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [8 January 2022 10:55 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/2 "2022-01-08T10:55:50Z")

</div>

Hi, I've not tried using pkg so it would interesting if you found out 🙂  
Normally I use electron - see [GitHub - dceejay/electron-node-red: Electron Node-RED template](https://github.com/dceejay/electron-node-red) - but I must admit I haven't really been maintaining it for a while so it may be well behind the curve of latest electron capability.  
The idea of my app is generally only expose the dashboard view - but the editor can be enabled if needed - but that really wasn't the idea... Of course although it i a "single app" it is still really just an embedded browser instance and node engine so anyone skilled could extract the underlying flow quite easily if they knew what they were doing and where to look. But it does make it easy to install and stops casual messing around.

---

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [8 January 2022 11:21 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/3 "2022-01-08T11:21:11Z")

</div>

Thanks @dceejay for prompt and informative response.

Perhaps, I am still trying to do it and searching for it on how am I going to package it into "one" executable file.

Hoping for someone here in our community able to do it 🙂  
Thanks and best regards!  
Henjoe

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 January 2022 11:57 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/4 "2022-01-08T11:57:33Z")

</div>

> [@dceejay](#):
>
> Normally I use electron - see [GitHub - dceejay/electron-node-red: Electron Node-RED template](https://github.com/dceejay/electron-node-red) - but I must admit I haven't really been maintaining it for a while so it may be well behind the curve of latest electron capability.

Dave, maybe it would be easier to maintain a build script then people could do it themselves?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 January 2022 12:02 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/5 "2022-01-08T12:02:59Z")

</div>

Have you had a go? Using my alternate install should give you the kind of config and folder structure you need to get started.

However, this seems problematic:

> However your code may have `require(variable)` calls (so called non-literal argument to `require` ) or use non-javascript files (for example views, css, images etc).

Which implies that there would a LOT of work to do in order to identify all of the variable dependencies. uibuilder for example has many cases where it constructs a path to a package.json file and then imports it.

But, it would be worth just having a go and see if it works without too much config, you never know.

---

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [8 January 2022 12:50 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/6 "2022-01-08T12:50:46Z")

</div>

Hi @TotallyInformation I actually managed it using pkg.  
by adding this package.json  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/073918b7886c2875af4666e161ad395b47f867c6.png)

Then run "pkg ."

It has 3 outputs for different OS:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/2/92b3fe3fd87e4429693af8cf948eebc77191613e.png)

then I can use the .exe file on my command prompt, I just need to put --userDir arguments.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38d361e03c0f6e2ae2a65566dad68d395c34ed5b.png)

And it works just like "npm start" on your alternate-installer.

The advantage of doing this is you just have to copy the node-red-master-win.exe to any other computer along with the "data" folder. and you can run node-red on any computer 🙂  
Without installing nodejs.

Thanks!

Regards,  
Henjoe

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [8 January 2022 13:03 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/7 "2022-01-08T13:03:03Z")

</div>

Well the readme starts with a section on how to wrap up an existing project - so there is that...

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [8 January 2022 21:04 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/8 "2022-01-08T21:04:29Z")

</div>

> [@Henjoe](#):
>
> The advantage of doing this is you just have to copy the node-red-master-win.exe to any other computer along with the "data" folder. and you can run node-red on any computer

The downside, of course, is that you now have to regularly update, rebuild and redistribute it.

Much better, where possible, to have a server-based service with users accessing it via only a browser. In our work environment, our standards say that "thick clients" are not permitted without special permission. This is due to the cost of maintaining them. If you do have to have a thick client (perhaps because your users have to work sometimes without network access), there must be a built-in update mechanism. With a node.js based application, this is really hard to monitor and assure since a typical node.js app has many dependent packages any of which may have serious security or other issues as might node.js itself.

In its native form, it is relatively easy to assure that node.js, Node-RED and all of the other components are up-to-date.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [8 January 2022 22:56 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/9 "2022-01-08T22:56:32Z")

</div>

There are also now well developed built in update mechanisms in electron ( as used by vs-code etc) . ( though not built into my example app ).

---

<div class="post-metadata">

### Author: ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)
#### Post date: [9 January 2022 01:08 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/10 "2022-01-09T01:08:24Z")

</div>

> [@Henjoe](#):
>
> The advantage of doing this is you just have to copy the node-red-master-win.exe to any other computer along with the "data" folder. and you can run node-red on any computer 🙂  
> Without installing nodejs.

That's good news. I last used **pkg** for a video streaming project (unrelated to node-red) about 3 years ago. Previously, they had issues packaging all of the files and any c++ node addons, but it had worked good enough for me. It seems they have come a long way if it can package something as complicated as node-red.

---

<div class="post-metadata">

### Author: ![Henjoe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henjoe/32/52335_2.png) [@Henjoe](https://discourse.nodered.org/u/Henjoe)
#### Post date: [9 January 2022 03:10 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/11 "2022-01-09T03:10:57Z")

</div>

I TotallyAgree with your point @TotallyInformation😃

In my case, I just don't want the users to update anything on the node-red project 🙂  
All programming, modules and etc are already done, and I just want them to use it "one-click" away 🙂

Regards,  
Henjoe

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 January 2022 03:11 UTC](https://discourse.nodered.org/t/can-i-package-whole-nodered-project-using-pkg-node/56271/12 "2022-01-23T03:11:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
