Starting a node file on boot?

How would I start a node.js program on boot?

node myprogram.js
--works via ssh

I tried putting this in rc.local so far

node /complete/path/to/myprogram.js &

I'm sure there is a little more to it then this (because that doesn't work). The rest of the internet seem to have squirrelly answers that have more to do with something with bash on it, or editing init.d.

I got a python program working on start by adding a !# something something to the top of the file, I could only hope it were that easy with node?

[quote author=Paul Beaudet link=msg=2424821 date=1444092595]I got a python program working on start by adding a !# something something to the top of the file, I could only hope it were that easy with node?[/quote] "#!" at the beginning of a file is called a shebang! or hash-bang. What follows is the name of the program that is to run the file. The system reads the first line, and if it sees a hash bang, it uses the rest of the line as a program name, and the file being executed as a parameter. For example, if the file test.py starts with "#!/usr/bin/python" and you type "test.py" at the command line, the system will read the first line of test.py, see the shebang, and then execute "/usr/bin/python test.py" to actually run the file. On the other hand, of you were to type "/usr/bin/python test.py" on the command line, then test.py wouldn't need a shebang at the beginning, since you are explicitly telling it which program to run.

Since, in your example, you are explicitly calling node, and passing the .js file as a parameter, it's likely that a shebang isn't going to help you.

I'm not familiar with node, so I can't answer your real question.

Thanks for the thoughts ShapeShifter, gives me a little more perspective.

I the meantime, the "I got this to work with python" comment gave me an idea

autostart.py

#!/bin/sh

from subprocess import call

call(["node", "/mnt/sda1/myProgram/serve.js"])

That works... haha

But maybe a real does exist solution exist? Or maybe that's as real as it gets for my attention span?

@Paul,
the simple answer is that node is NOT in your execution PATH, but python is. When debugging issues like this, you want to use the following commands.

which node - this tells you where in the execution PATH the command lives. If it is blank, then it is NOT in your execution path. If the command is not in the execution path, then you MUST use the FQFN (Fully Qualified File Name).

In the case of firing a script from rc.local, the PATH is restricted. This means the PATH you get from a shell is different than the PATH you get in rc.local.

In the case of rc.local, the PATH restriction is different because it is used as part of the boot process. During the boot process, it is not always clear where the user space is. You will likely find that node is stored in /usr/bin; and not /bin or /sbin, which is not userspace.

You can get more details by reading my NOTES: The Yún CLI Tools

I hope this is clear. If not please ask questions.
Jesse