Node.js Server Action not Working

Wappler 5.0
Windows 11

I’m starting a new Node.js project and this is my first one so I’m not 100% sure on what I’m doing. LOL.

I have the site running with a basic template page and some content pages. All good. I then created a database connection which is working. I can open and tables in the database manager. Next I created a server action to query the database. This looked all good with the database tables etc showing up to create the query. I then created the server action in my template file, main.ejs and used that to populate a masonry.

When I load the page I get a 500 error. When I click on that it shows that it’s trying to load but the api folder is inside the app folder. image

I went back over to the server action and tried to open it in the browser and that goes to the same folder, without app. It also says to enable the debug flag, but that’s already on

Fixing this should be your focus. The page you mention is asking you to enable it, are you sure this option is enabled for your deployed target? Can you try to re-deploy?

I unticked it, reticked it and republished and that fixed the debug issue.

I then got this message.

“status”: “500”,
“message”: “Knex: run\n$ npm install mysql --save\nCannot find module ‘mysql’”,
“stack”: “Error: Knex: run\n$ npm install mysql --save\nCannot find module ‘mysql’\n at Client_MySQL.initializeDriver (/home/triptakers/nodevenv/\n at new Client (/home/triptakers/nodevenv/\n at new Client_MySQL (/home/triptakers/nodevenv/\n at knex (/home/triptakers/nodevenv/\n at App.setDbConnection (/home/triptakers/\n at App.getDbConnection (/home/triptakers/\n at (/home/triptakers/\n at App._exec (/home/triptakers/\n at App.exec (/home/triptakers/\n at App.define (/home/triptakers/”

I did the npm install mysql in the terminal and published but I’m still getting the same error.

What terminal? Wappler terminal? Or via SSH to your server? How are you hosting this app?

It’s on a reseller hosting. I did that in the Wappler terminal. Thanks for your help!

No problem! I think the Wappler terminal is only for your local computer, so you’ll have to go to your hosting control panel and find an option to install NPM packages, or SSH access if your hosting provider allows it

Ah. Ok. I’m so not clear about how NPM works. I thought it basically just downloaded files and so when I published to the server the files would then be published?


Might not be true because the node_modules folder might be excluded from upload by Wappler (you can check with FTP), don’t know for sure as I don’t use Wappler’s deployment. The reason for this is some modules might need to be recompiled depending on the server/hosting provider you use (e.g.: due to different operative systems, like if you work on Windows and deploy to a Linux machine). The majority of modules work without compilation, but some specific ones (which might include MySQL libraries and such) might require compilation

On your hosting control panel there should be a button to install NPM packages, it’ll read from package.json file that Wappler should have uploaded

That makes sense. Thanks. And it does look like the node_modules folder doesn’t upload.

Apparently I need to install NPM via SSH but currently I can’t seem to login there so have put in a support ticket. I’ll get there eventually!

Ok - after the to and fro I had to log into my server via SSH, install node.js then NPM and finally mysql via NPM. Voila! It’s working.

Thanks for your help @Apple

No problem!

I think now you have 2 NodeJS installations on your server, because you had one NodeJS before. But glad it’s working though! Just something to keep in mind

You could also run “npm install” instead of “npm install mysql”, it’ll read from package.json - it might help you in the future