Node.js: Can't get a simple single query to display on remote (Knex?)

Node.js (v18.18.2 on remote)
MySQL
https://sandbox.lawryk.ca/websockets

Very simple page that works well on local Wappler server but the scores query gets a 500 error on remote server. I have debug enabled so that maybe someone can decipher the error message.

It’s just a very simple api that returns one record. Should show the scores and assign the values to the form inputs as well.

I’m stumped. Should be a very simple task.

Thanks in advance for any help.

Update: Updating the form also throws an error

This is what it should show from local server:

@George @Teodor @patrick

Hi Brad,

Just tried the url in your post and I also got the Knex error.

I have never tried hosting a node.js app via cPanel. Do you need to install Knex manually on the hosting server?

There should be a button on your control panel to install NPM modules, click it

Error for future reference:

Knex: run\n$ npm install mysql --save\nCannot find module 'mysql'

Yes, there is a button and everything installs ok without errors.

It’s time to summon George or Teodor to ask why “mysql” is not in package.json, they’re the ones that understand why Wappler does things a certain way :smile:

1 Like

I regularly have to manually install mysql on newly created node servers. So used to it I stopped thinking of it as a bug
Normally just:

npm install mysql --save

fixes issues

1 Like

Thanks Brian, and where do you run that? In cPanel terminal?

Yes, I open terminal from the cPanel menu and type it there

In the NodeJS section of your cPanel, do you find any information regarding a “virtual environment”? There should be a command you have to run first

Or, you can find npm’s binary here:

/opt/cpanel/ea-nodejs**/bin/

But the ** need to be replaced with the NodeJS version. It’s better if you cd /opt/cpanel and then type ls to list the folders, and there you find the NodeJS version and cd into it. But you can’t run install mysql here in this directory, you need to go your project’s directory, and call the npm binary from there using the full path of it

Reference:

Sorry Brad, no access to a computer at present (using phone) so can’t investigate further.

1 Like

No problem, I appreciate your time. It’s not critical. It’s just a hard sell for me to move to node if I can’t get a simple query to work :wink:

Or an easier solution is just to manually modify package.json to add “mysql” - check how’s on your local computer (you could even copy the entire file). And then click the button to install NPM modules

Wouldn’t the packages file on the server already be the same as on local? I’m not comfortable editing that file as I have no idea what any of it means :wink:

It should, but isn’t, otherwise Knex would be working

Copy from local to remote

Wappler tries to optimize package.json to remove packages that are unused. Somehow, Wappler think MySQL isn’t needed on the remote, that’s the explanation to your problem, the reason why this happens needs to be explained by George or Teodor

Hmmm, there is nothing in the local package file referring to MySQL either.

Aren’t you using MySQL locally? Is the query running locally?

Everything works perfectly locally. The database is a remote database on the server.

It’s weird there’s no mention of “mysql” in the local package.json, maybe it was removed sometime later, for unknown reasons…

Well, then my help terminates here :slight_smile: Your only option is to run that NPM command, or if you can wait for George/Teodor…

1 Like

Thanks @Apple, much appreciated. I will await help from the team. It’s pretty much :beers: time anyways.