Nodejs hosting with Hetzner on KonsoleH

I’m trying to figure out how deploying is working with my Hetzner Managed Server (https://wiki.hetzner.de/index.php?title=Installation_gängiger_Software_(Managed_Server)#node.js).

The only information I got from Hetzner is how to install Node.js Server on my account. Installation was successful. But now I don’t know what to do next.

Ftp root is as follows:

I didn’t understand where the app folder should be. In the public_html or in the root?

Hetzner sadly is one of the unique control panels I avoid like the plague, as it is different to everyone and everything else around, I will take a little look though as I have some Hetzner accounts and see if i can work it out for you.

1 Like

Hi Paul,

I got it working :slight_smile:

I will make some screenshots. The only problem I have at the moment is the bug you already posted because of restarting the server on upload.

The target is set to the correct production server.

You should place the node app outside of the public_html folder, if you place it in there then all files are accessible over the internet and they could download all the files that contain your credentials.

The public_html folder a folder from the apache/nginx server where it serves it files from, the node app has it’s own server and public folder.

2 Likes

Same thing as Patrick says, you need to be outside the /public_html/ folder rather.

And the restart.txt thing, im still not sure, because i finally got mine working by altering the home directory name from /app/ to /nodejsapp/ rather to avoid situations where wappler is trying to access /home/paul/app/app/api/ and now mine is working perfectly every time, however doing the exact same procedure on Brians project still has the same issue, so very strange, can not quite see how or why.

@patrick & @psweb thank you for your hint about the path!

I changed the path and restarted the server. Everything works fine besides the problem with restart.txt.

What I don’t understand is that I have to install fs-extra (npm install fs-extra) because otherwise I get an error on starting the server. Is this a known issue?

I installed Ruby once upon a time on Hetzner and also had to install an additional fs(file system) thing, so I think it is normal, as Apache automatically wants to look at the public_html directory, so the file system extra needs to bypass that as far as I know.

Oh and congratulations on getting this working.

Just that restart.txt thing we all seem to be fiddling with, except for me now, because mine suddenly works, haha.

1 Like

The only thing at hetzner you have to change, is that you change/create your .htaccess file in the document root of your site:

RewriteEngine on
RewriteRule   ^(.*)  http://localhost:3000/$1 [P]
1 Like

@MH2ag out of interest, with Hetzner did you have to change the index.js file name to app.js

No, it does work with index.js. I don’t get the restart.txt error if I stop my local Node.js first.

What I’m struggling at the moment is how to start the Node.js server. If I start it manually in the terminal with node index.js it works, but if I close the terminal it stops working :frowning:

In cPanel it is always started, the only time I have had to do something like what you are experiencing was with docker, something like

$ docker-cloud service set — autorestart ALWAYS (name or uuid)

But with Node I have not had that issue, maybe hetzner tech support will have to answer that one because their control panel is pretty different and I imagine finding the right command may be tricky.

Edit: index.js holds this

const server = require('./lib/server');

server.start();

Which is to do with starting the Node Server, maybe just as a test duplicate index.js and rename the duplicate to app.js.
My Node server will not start without doing this.

if it’s any consolation I have the same error. FTP works OK, i can publish to the live site without problem but when saving server actions i get the same error message

@George will check this :slight_smile:

1 Like

I don’t get the restart.txt error anymore if I stop the local Node.js server before I switch the target to production. But restart does not work…

@psweb I changed index.js to app.js but there is no difference. Did you restart the server manually first?

1 Like

wow, yes, killing the local server before switching to live target solves the issue, no error message!

1 Like

Yes currently you have to kill the local server before deploy to remote.

As otherwise the same local server gets also restarted by restart.txt and it deletes the file so it isn’t available for the ftp

We will address the issue but will probably be doing the same - kill the local server when you switch targets

2 Likes

Not a problem now we know what the issue is, would be nice to kill the server automatically on target switch if possible but then again it would then have to be restarted every time someone switches back to the local server

3 Likes

That is exactly what I plan to do

1 Like

Just happy the issue was figured out, I must have spent 5 hours trying different things, felt like playing level 1228 of candy crush soda saga for 2 weeks all over again.

2 Likes

@Hyperbytes & @psweb
Does your remote Node.js server restart?