# Auto start corresponding to "node-red-pi --max-old-space-size=256"

**URL:** https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687
**Category:** General
**Created:** [27 July 2022 10:45 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687 "2022-07-27T10:45:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Jeff2](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeff2](https://discourse.nodered.org/u/Jeff2)
#### Post date: [27 July 2022 10:45 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/1 "2022-07-27T10:45:43Z")

</div>

Hi,

My Raspberry Pi doesn't like the "node-red-start" command line (provides errors), but is OK with "node-red-pi --max-old-space-size=256" command line.

Therefore, I would like to know what is the corresponding command line for an autostart of the service with this option ?

Thanks for your support

---

<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: [27 July 2022 10:49 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/2 "2022-07-27T10:49:42Z")

</div>

For auto-start, you should have a systemd service script. I think that Dave's installer script sets that up so you can look in that. You could also look in my alternate installer repo which has an example script file with some extended features.

By using systemd, node-red is started at bootup and restarted on fail. You can manually restart with a command too ( the example package.json file in my alt installer should have the commands listed I think).

And the max-old-space may not be needed with newer versions of node.js so you may wish to try without first.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 11:06 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/3 "2022-07-27T11:06:17Z")

</div>

> [@Jeff2](#):
>
> My Raspberry Pi doesn't like the "node-red-start" command line

Did you install it using the [recommended install script](https://nodered.org/docs/getting-started/raspberrypi)?

---

<div class="post-metadata">

### Author: ![Jeff2](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeff2](https://discourse.nodered.org/u/Jeff2)
#### Post date: [27 July 2022 11:14 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/4 "2022-07-27T11:14:12Z")

</div>

Yes I followed this one

---

<div class="post-metadata">

### Author: ![Jeff2](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@Jeff2](https://discourse.nodered.org/u/Jeff2)
#### Post date: [27 July 2022 11:21 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/5 "2022-07-27T11:21:08Z")

</div>

Not working without:

node-red-start

Start Node-RED

Once Node-RED has started, point a browser at [http://192.168.1.98:1880](http://192.168.1.98:1880)  
On Pi Node-RED works better with the Firefox or Chrome browser

Use node-red-stop to stop Node-RED  
Use node-red-start to start Node-RED again  
Use node-red-log to view the recent log output  
Use sudo systemctl enable nodered.service to autostart Node-RED at every boot  
Use sudo systemctl disable nodered.service to disable autostart on boot

To find more nodes and example flows - go to [http://flows.nodered.org](http://flows.nodered.org)

Starting as a systemd service.  
\<--- Last few GCs ---\>  
[3067:0x5971f70] 68 ms: Mark-sweep 0.3 (2.8) -\> 0.3 (2.8) MB, 1.3 / 0.0 ms (average mu = 0.254, current mu = 0.026) allocation failure GC in old space requested  
[3067:0x5971f70] 70 ms: Mark-sweep (reduce) 0.3 (2.8) -\> 0.3 (1.8) MB, 1.5 / 0.0 ms (average mu = 0.151, current mu = 0.023) last resort GC in old space requested  
[3067:0x5971f70] 71 ms: Mark-sweep (reduce) 0.3 (1.8) -\> 0.3 (1.8) MB, 1.2 / 0.0 ms (average mu = 0.097, current mu = 0.022) last resort GC in old space requested  
\<--- JS stacktrace ---\>  
FATAL ERROR: CALL\_AND\_RETRY\_LAST Allocation failed - JavaScript heap out of memory  
nodered.service: Main process exited, code=killed, status=6/ABRT  
nodered.service: Failed with result 'signal'.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 12:49 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/6 "2022-07-27T12:49:26Z")

</div>

That is unusual. What does the command  
`node -v`  
show?  
Can you post the file /var/log/nodered-install.log please. If that file is empty then try /var/log/nodered-install.log.1

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 12:51 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/7 "2022-07-27T12:51:08Z")

</div>

Also what happens if you just run the command  
`node-red`

---

<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: [27 July 2022 12:55 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/8 "2022-07-27T12:55:49Z")

</div>

> [@Jeff2](#):
>
> Use sudo systemctl enable nodered.service to autostart Node-RED at every boot

And there is the answer to the question about auto-starting.

> [@Colin](#):
>
> That is unusual

Yes, I've never seen NR fail so early on with a heap allocation failure.

Can you add the following code early in the settings.js file? (Must be outside the export object).

```auto
/** Optionally display the Node.js/v8 engine heap size on startup */
const v8 = require('v8')
console.info(`V8 Total Heap Size: ${(v8.getHeapStatistics().total_available_size / 1024 / 1024).toFixed(2)} MB`)
let mem = process.memoryUsage()
const formatMem = (m) => ( m/1048576 ).toFixed(2)
console.info(`Initial Memory Use (MB): RSS=${formatMem(mem.rss)}. Heap: Used=${formatMem(mem.heapUsed)}, Tot=${formatMem(mem.heapTotal)}. Ext C++=${formatMem(mem.external)}`)

```

Then report the output (will be in the node-red log).

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 14:40 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/9 "2022-07-27T14:40:05Z")

</div>

Run `sudo nano /lib/systemd/system/nodered.service`

Verify that these lines are present, if not then add them:

```auto
Environment="NODE_OPTIONS=--max_old_space_size=256"
Environment="PI_NODE_OPTIONS=--max_old_space_size=256"

```

Then run

```auto
sudo systemctl daemon-reload
node-red-stop
node-red-start

```

You can also run `sudo systemctl enable nodered.service` to auto-start every time it boots.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 14:45 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/10 "2022-07-27T14:45:19Z")

</div>

> [@HaroldPetersInskipp](#):
>
> Verify that these lines are present, if not then add them  
> Environment="NODE\_OPTIONS=--max\_old\_space\_size=256"  
> Environment="PI\_NODE\_OPTIONS=--max\_old\_space\_size=256"

If the first one is not there then we need to know why, hence my request for the other information. Has the second one been added to the script recently? It is not present on my Pis.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 14:48 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/11 "2022-07-27T14:48:34Z")

</div>

On my Pi 4 I only have

```auto
Environment="NODE_OPTIONS=--max_old_space_size=2048"

```

But my Pi 0 W's had this by default

```auto
Environment="PI_NODE_OPTIONS=--max_old_space_size=256"

```

So I manually edited them to include the first line.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 14:54 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/12 "2022-07-27T14:54:51Z")

</div>

Did those come from the install script?

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 15:00 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/13 "2022-07-27T15:00:14Z")

</div>

Yes, Node-RED is installed on all of them using the officially provided install script. However, due to Node no longer supporting armv6 hardware, I have installed an unofficial build of Node v16.11.0 with my own script (I am unaware if this may have an effect on it) for the Pi 0 W's.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 15:09 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/14 "2022-07-27T15:09:31Z")

</div>

The script should cope with armv6 by downloading nodejs from an alternative source.

The service file comes from [here](https://raw.githubusercontent.com/node-red/linux-installers/master/resources/nodered.service) I believe, and the space setting is adjusted based on the amount of memory available. Perhaps that calculation has gone wrong. @Jeff2 could you copy/paste the service file please so we can have a look at it?

@HaroldPetersInskipp, I don't know where your PI\_NODE\_OPTIONS entry has come from.

Note that if you re-run the script it will overwrite your changes to the service file. If you want to amend something in an installed service file it is better to use the systemd override feature to do that, then the mods will not get removed if you rerun the script. Look up `systemctl edit` for how to do that.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 15:16 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/15 "2022-07-27T15:16:24Z")

</div>

It came from me manually editing it in. I believe the install script warns the user and leaves the service file alone if it detects it has been edited.

Basically what I'm trying to say is that my installs on my Pi 0 W's may be unconventional, and should not be solely relied upon for debugging a installation issue.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 15:31 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/16 "2022-07-27T15:31:24Z")

</div>

> [@HaroldPetersInskipp](#):
>
> It came from me manually editing it in

Where is that env var (PI\_NODE\_OPTIONS) used?

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 15:46 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/17 "2022-07-27T15:46:05Z")

</div>

I don't know tbh, I think that line was already there, as it is referenced here: [Customising the Raspberry Pi service : Node-RED](https://nodered.org/docs/faq/customising-systemd-on-pi)

I only added the top line `Environment="NODE_OPTIONS=--max_old_space_size=256"`

I think `node-red-start` uses one and `node-red-pi` uses the other?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 July 2022 15:50 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/18 "2022-07-27T15:50:56Z")

</div>

I think there is an error in that page, if you look at the first and third boxes you will see that in the first it is called PI\_NODE\_OPTIONS and in the third the same line has NODE\_OPTIONS. I suspect that the former may be from a very old version of the file. I am fairly confident that the only one that matters is NODE\_OPTIONS.

---

<div class="post-metadata">

### Author: ![HaroldPetersInskipp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/haroldpetersinskipp/32/42319_2.png) [@HaroldPetersInskipp](https://discourse.nodered.org/u/HaroldPetersInskipp)
#### Post date: [27 July 2022 15:53 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/19 "2022-07-27T15:53:58Z")

</div>

I thought that might be the case, so for redundancy I just put both (assuming it wouldn't hurt anything to have an extra variable).

---

<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: [27 July 2022 17:23 UTC](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687/20 "2022-07-27T17:23:19Z")

</div>

(docs now fixed)

[Next page](https://discourse.nodered.org/t/auto-start-corresponding-to-node-red-pi-max-old-space-size-256/65687.md?page=2)
