Nodejs hosting with Hetzner on KonsoleH

My remote one yes.

1 Like

I will need the support of Hetzner then. I will see what they tell me tomorrow.

1 Like

Sadly, i think it is something specific to their module, so i think it would be safest.

EDIT: maybe look at this @MH2ag, looks like you could use the same PM2 commands commonly used for Docker to run Node.js as a service rather than an Application which is what gives it the auto restart

1 Like

I just found some interesting ideas I will have to check! :grinning:

@psweb Thank you for the link!

1 Like

I want to give you an update on my Hetzner deployment:

I am now using pm2 (pm2 install pm2@latest -g) for start and restart of the server. The restart with Wappler still does not work for me.

My actual problem is with the module fs-extra.

If I start the server with node index.js I get the following error:

Error: Cannot find module 'fs-extra'
Require stack:
- /usr/home/vewafm/nodejsapp/lib/setup/config.js
- /usr/home/vewafm/nodejsapp/lib/server.js
- /usr/home/vewafm/nodejsapp/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1029:15)
    at Function.Module._load (internal/modules/cjs/loader.js:898:27)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at Object.<anonymous> (/usr/home/vewafm/nodejsapp/lib/setup/config.js:2:12)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/home/vewafm/nodejsapp/lib/setup/config.js',
    '/usr/home/vewafm/nodejsapp/lib/server.js',
    '/usr/home/vewafm/nodejsapp/index.js'

If I try to install fs-extra I get the following::

npm install fs-extra

> sqlite3@4.2.0 install /usr/home/vewafm/nodejsapp/node_modules/sqlite3

> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download

node-pre-gyp WARN Tried to download(403): https://mapbox-node-binary.s3.amazonaws.com/sqlite3/v4.2.0/node-v83-linux-x64.tar.gz

node-pre-gyp WARN Pre-built binaries not found for sqlite3@4.2.0 and node@14.4.0 (node-v83 ABI, glibc) (falling back to source compile with node-gyp)

make: Entering directory '/usr/home/vewafm/nodejsapp/node_modules/sqlite3/build'

ACTION deps_sqlite3_gyp_action_before_build_target_unpack_sqlite_dep Release/obj/gen/sqlite-autoconf-3310100/sqlite3.c

TOUCH Release/obj.target/deps/action_before_build.stamp

CC(target) Release/obj.target/sqlite3/gen/sqlite-autoconf-3310100/sqlite3.o

Release/obj/gen/sqlite-autoconf-3310100/sqlite3.c:14012:19: fatal error: stdio.h: No such file or directory

compilation terminated.

make: *** [deps/sqlite3.target.mk:143: Release/obj.target/sqlite3/gen/sqlite-autoconf-3310100/sqlite3.o] Error 1

make: Leaving directory '/usr/home/vewafm/nodejsapp/node_modules/sqlite3/build'

gyp ERR! build error

gyp ERR! stack Error: `make` failed with exit code: 2

gyp ERR! stack at ChildProcess.onExit (/usr/home/vewafm/.linuxbrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)

gyp ERR! stack at ChildProcess.emit (events.js:315:20)

gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)

gyp ERR! System Linux 4.19.0-9-amd64

gyp ERR! command "/usr/home/vewafm/.linuxbrew/Cellar/node/14.4.0/bin/node" "/usr/home/vewafm/.linuxbrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v83"

gyp ERR! cwd /usr/home/vewafm/nodejsapp/node_modules/sqlite3

gyp ERR! node -v v14.4.0

gyp ERR! node-gyp -v v5.1.0

gyp ERR! not ok

node-pre-gyp ERR! build error

node-pre-gyp ERR! stack Error: Failed to execute '/usr/home/vewafm/.linuxbrew/Cellar/node/14.4.0/bin/node /usr/home/vewafm/.linuxbrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)

node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/home/vewafm/nodejsapp/node_modules/node-pre-gyp/lib/util/compile.js:83:29)

node-pre-gyp ERR! stack at ChildProcess.emit (events.js:315:20)

node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1051:16)

node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)

node-pre-gyp ERR! System Linux 4.19.0-9-amd64

node-pre-gyp ERR! command "/usr/home/vewafm/.linuxbrew/Cellar/node/14.4.0/bin/node" "/usr/home/vewafm/nodejsapp/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"

node-pre-gyp ERR! cwd /usr/home/vewafm/nodejsapp/node_modules/sqlite3

node-pre-gyp ERR! node -v v14.4.0

node-pre-gyp ERR! node-pre-gyp -v v0.11.0

node-pre-gyp ERR! not ok

Failed to execute '/usr/home/vewafm/.linuxbrew/Cellar/node/14.4.0/bin/node /usr/home/vewafm/.linuxbrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/home/vewafm/nodejsapp/node_modules/sqlite3/lib/binding/node-v83-linux-x64 --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v83' (1)

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/fsevents):

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! sqlite3@4.2.0 install: `node-pre-gyp install --fallback-to-build`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the sqlite3@4.2.0 install script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Any idea what I’m doing wrong?

It works with static html files, but I get the following error in the browser with using templates like in @Teodor example:

{"status":"404","message":"/index.html not found."} 

Same site works on local NodeJS Server an Heroku.

I am just quickly re doing my test server setup with the newer ejs and will report back if I find any similar issues @MH2ag

1 Like

It isn’t the fs-extra module But the sqlite3 module that tries to compile on your server however it seems you don’t have the compile tools installed.

It is an optional module only when you use SQLite so you can just remove it from your package.json

And we use nodemon so you don’t have to use pm2

1 Like

Just out of interest, I just deleted my entire account from my WHM server as well as started a new Wappler project, so everything was totally fresh, did the install as per the cPanel instructions and everything went perfectly, made no difference that now I no longer have an index.html file, and instead have a ejs system.
Still needed the .npmrc and still had to use app.js rather than index.js, but very smooth transition, ensure dependencies did take some time to run, maybe 5 minutes, so i was a little concerned but it completed successfully after the wait.
Restart.txt is working perfectly too.

1 Like

Out of interest @MH2ag what type of account are you running with Hetzner who i think are now called Xneelo, is it a managed server, self managed server or just a standard shared hosting website?

Hi @psweb,
it is a managed server account (own server but managed by hetzner). I had a root server before but didn’t have the time to look for security and updates.

1 Like

Yeah I do not think you should have such an issue with that, What sort of management interface have you got on it, CentOS or something, sorry only ever had normal little shared hosting accounts with Hetzner, so only ever seen their KonsoleH thing which I kind of hate to be honest.

I have a KonsoleH interface :frowning:

Thanks for the information. This already helped me a lot.

Do you have any idea why I get

{"status":"404","message":"/index.html not found."}

I created a fresh site like @psweb. Could it be something with cache? I only have ejs files, no index.html

you probably don’t have a default route.

I think we create one for new project based on template. Will check for blank projects

I still have problems with my Node.js deployment of my testsite to Hetzner. The same site works locally, Heroku and my IIS with proxy.

I still get the 404 error with Index.html not found. I only have .ejs pages. The routes should be correct, otherweise it would not work on the other deployment sites.

The only difference is that with Hetzner I have to use Apache with the following recommended configuration in the .htaccess of the document root.

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

Could it be this?

I found the answer myself. It was indeed the wrong .htaccess configuration which was recommended by Hetzner.

The following configuration works:

DirectoryIndex disabled
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:3000/$1 [P,L]
RewriteRule ^$ http://localhost:3000/ [P,L]

https://html.developreference.com/article/10474320/How+to+serve+Express+node+API+to+subdomain%3F

1 Like

Was there anything else you needed to do specifically, maybe if you would not mind, considering you have been through quite a bit to get this working, could you add a Hetzner specific tutorial here.

1 Like

I will make a tutorial as soon as I found out the best solution for starting node as a service in the background. I‘m still experimenting…

Starting node with this command seems to work:

nohup nodemon index.js </dev/null &

First upload the site

Then in Plesk, go to the Node.js page

image

Set the correct site root (1) and the startup file (2) and install Node.js (3)

image

Edit: I forgot to say that the app directory needs to be created before you can assign it in the last step.

Hi Ben, sorry just trying to figure out if this is different to Post 1 which is Teodors Plesk guide, mine is the second guide for cPanel, what we are trying to get a guide for now is the Hetzner hosting accounts which use the proprietary KonsoleH control panel.
And that is where Marcel is finding an issue with the server startup side of things, right now he has to do it manually.