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 https://sandbox.triptakers.travel/api/tripbits but the api folder is inside the app folder.
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/sandbox.triptakers.travel/10/lib/node_modules/knex/lib/client.js:192:13)\n at new Client (/home/triptakers/nodevenv/sandbox.triptakers.travel/10/lib/node_modules/knex/lib/client.js:73:12)\n at new Client_MySQL (/home/triptakers/nodevenv/sandbox.triptakers.travel/10/lib/node_modules/knex/lib/dialects/mysql/index.js:21:1)\n at knex (/home/triptakers/nodevenv/sandbox.triptakers.travel/10/lib/node_modules/knex/lib/knex-builder/Knex.js:12:28)\n at App.setDbConnection (/home/triptakers/sandbox.triptakers.travel/lib/core/app.js:296:27)\n at App.getDbConnection (/home/triptakers/sandbox.triptakers.travel/lib/core/app.js:315:25)\n at App.select (/home/triptakers/sandbox.triptakers.travel/lib/modules/dbconnector.js:14:25)\n at App._exec (/home/triptakers/sandbox.triptakers.travel/lib/core/app.js:491:57)\n at App.exec (/home/triptakers/sandbox.triptakers.travel/lib/core/app.js:427:20)\n at App.define (/home/triptakers/sandbox.triptakers.travel/lib/core/app.js:417:20)”
I did the npm install mysql in the terminal and published but I’m still getting the same error.
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
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