Node.js app setup with sPanel

I couldn’t figure out how to setup node.js app in sPanel. I found information about cPanel or Plesk. But sPanel is different. After deploying my app on server, I’m getting this error:


Error: Cannot find module ‘dotenv’
Require stack:

  • /home/nsritik/nodejsapi/lib/server.js
  • /home/nsritik/nodejsapi/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:931:15)
    at Module.Hook._require.Module.require (/usr/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:61:29)
    at require (internal/modules/cjs/helpers.js:107:18)
    at Object. (/home/nsritik/nodejsapi/lib/server.js:2:5)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1143:10)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at Module.Hook._require.Module.require (/usr/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [
    ‘/home/nsritik/nodejsapi/lib/server.js’,
    ‘/home/nsritik/nodejsapi/index.js’
    ]
    }

  1. sPanel Node Setup

  1. Deployed App

  1. directory (home/user/nodejsapi)

You need to npm install, find a button to “npm install” (click Actions to see if you find it)

1 Like

Thanks for your help. It works. Now the project is online. But I’m getting this message instead of index.html page. @patrick @Teodor

It’s been about a week, I’m still stuck. Please Fins a solution for me @patrick @Apple @franse

Silly suggestion, have you tried setting your application path to the actual file instead of the directory, so instead of home/user/nodejsapi try home/user/nodejsapi/index.js or home/user/nodejsapi/app, its just a guess but worth a try.

1 Like

This my setup for my Plesk panel. Maybe it will give you a few ideas.

image

And this is the file structure.

The first mention of app in the first image (app/public) refers to the app in the app folder.

The second mention of app refers to the app in the home directory.

2 Likes

Explain that index.html, Wappler doesn’t use index.html

Does it work on your local computer? And at what URL?

I agree with @ben, your directory called nodejsapi should actually be called app, at least thats how cPanel needs it too.
Then the application path would be /home/nsritik/app and not /home/nsritik/nodejsapi

And for testing you will navigate to the url Domain only, like http://example.com and not http://example.com/nodejsapi or http://example.com/app

This means your file manager will show a folder called app in your home directory, and inside that folder is the second app folder auto generated by Wappler

1 Like

Thanks @psweb. I used your silly suggestion :wink: and unfortunately It worked for me. :joy:

Thanks a lot again.

1 Like

In order to deploy a node.js app to remote server, I was successful. Thanks to @psweb. But I’m facing issues in sever connection. I’m unable to register or login a user neither remote server nor from local server. Please correct me if I’m doing something wrong.

  1. User registration form

  1. user_registration.json file

  1. CORS

  1. https://website.com/login

  1. http://localhost:3050 (user registration)

Error 500 message on the local host suggests there is an issue with either the form values not being submitted correctly or one of the API steps is not executing successfully.

Do you see any error under response tab for the user_registration API (on the local host)? Also try the registration process by disabling the Send Mail step.

I would suggest to first get the user registration and login processes working correctly on the localhost before publishing these to a remote server. Once these ateps are working correctly on the localhost, then it’s easier to identify any issues you might encounter on the remote host.

Just as a personal preference, rather name files as user-login and directories as user-area and avoid the camelcase style naming for files and directories, its fine to use camelcase as class names or IDs etc., although even with that i tend to use lowercase with _ as a separator, like user_registration_form.

Camelcase can cause issues with query parameters as well as on certain server systems where there is no difference between them.

So at least for your 404 error that may help. For the rest please supply screenshots of your developer console as you have but showing the payload and preview tabs and not only the headers, incase there is some error in there we can try track for you.

1 Like

I’ve changed from userSecurity to user_security. But still getting 404 error.

It says:

But file is on server and in right directory:

what should be the issue?

Just in case…

Can you check carefully (or share screenshot) in your Workflow panel that your paths are ok per target?

This is target setting:

Database connection:

Once you accidently pictured part of the serveraction…

There should appear your api data… no?

This is error 500 responce:

{

"status": "500",

"message": "Knex: run\n$ npm install mysql --save\nCannot find module 'mysql'\nRequire stack:\n- /home/user/public_html/node_modules/knex/lib/dialects/mysql/index.js\n- /home/user/public_html/node_modules/knex/lib/dialects/index.js\n- /home/user/public_html/node_modules/knex/lib/knex-builder/internal/config-resolver.js\n- /home/user/public_html/node_modules/knex/lib/knex-builder/Knex.js\n- /home/user/public_html/node_modules/knex/lib/index.js\n- /home/user/public_html/node_modules/knex/knex.js\n- /home/user/public_html/lib/core/db.js\n- /home/user/public_html/lib/core/app.js\n- /home/user/public_html/lib/core/middleware.js\n- /home/user/public_html/lib/setup/routes.js\n- /home/user/public_html/lib/server.js\n- /home/user/public_html/index.js",

"stack": "Error: Knex: run\n$ npm install mysql --save\nCannot find module 'mysql'\nRequire stack:\n- /home/user/public_html/node_modules/knex/lib/dialects/mysql/index.js\n- /home/user/public_html/node_modules/knex/lib/dialects/index.js\n- /home/user/public_html/node_modules/knex/lib/knex-builder/internal/config-resolver.js\n- /home/user/public_html/node_modules/knex/lib/knex-builder/Knex.js\n- /home/user/public_html/node_modules/knex/lib/index.js\n- /home/user/public_html/node_modules/knex/knex.js\n- /home/user/public_html/lib/core/db.js\n- /home/user/public_html/lib/core/app.js\n- /home/user/public_html/lib/core/middleware.js\n- /home/user/public_html/lib/setup/routes.js\n- /home/user/public_html/lib/server.js\n- /home/user/public_html/index.js\n at Client_MySQL.initializeDriver (/home/user/public_html/node_modules/knex/lib/client.js:202:13)\n at new Client (/home/user/public_html/node_modules/knex/lib/client.js:83:12)\n at new Client_MySQL (/home/user/public_html/node_modules/knex/lib/dialects/mysql/index.js:21:1)\n at knex (/home/user/public_html/node_modules/knex/lib/knex-builder/Knex.js:16:28)\n at App.setDbConnection (/home/user/public_html/lib/core/app.js:406:27)\n at App.getDbConnection (/home/user/public_html/lib/core/app.js:425:25)\n at App.notexists (/home/user/public_html/lib/validator/db.js:15:25)\n at Object.validateRule (/home/user/public_html/lib/validator/index.js:93:36)\n at Object.validateData (/home/user/public_html/lib/validator/index.js:29:37)\n at App.validate (/home/user/public_html/lib/modules/validator.js:9:26)"

}

Probably you changed something and the 404 error became 500

You posted the remote’s stuff before, BUT the DB connection while on Development…

Please first check that topic and the solution from Teodor here:

I need to enter host ip address in order to get connected.

When I’m using localhost or 127.0.0.1. Connection refuses.

Update:

After npm install mysql --save on vps ssh. I’m able to register user from https://localhost:3050 but on actual address https://mywebsite.com It’s not working. You can check error here. It says connection error. Doesn’t know why…

{

"status": "500",

"code": "ER_ACCESS_DENIED_ERROR",

"message": "ER_ACCESS_DENIED_ERROR: Access denied for user 'databaseuser'@'remoteserver.com' (using password: YES)",

"stack": "Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'databaseuser'@'remoteserver.com' (using password: YES)\n at Handshake.Sequence._packetToError (/home/user/public_html/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)\n at Handshake.ErrorPacket (/home/user/public_html/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)\n at Protocol._parsePacket (/home/user/public_html/node_modules/mysql/lib/protocol/Protocol.js:291:23)\n at Parser._parsePacket (/home/user/public_html/node_modules/mysql/lib/protocol/Parser.js:433:10)\n at Parser.write (/home/user/public_html/node_modules/mysql/lib/protocol/Parser.js:43:10)\n at Protocol.write (/home/user/public_html/node_modules/mysql/lib/protocol/Protocol.js:38:16)\n at Socket.<anonymous> (/home/user/public_html/node_modules/mysql/lib/Connection.js:88:28)\n at Socket.<anonymous> (/home/user/public_html/node_modules/mysql/lib/Connection.js:526:10)\n at Socket.emit (events.js:400:28)\n at addChunk (internal/streams/readable.js:293:12)\n --------------------\n at Protocol._enqueue (/home/user/public_html/node_modules/mysql/lib/protocol/Protocol.js:144:48)\n at Protocol.handshake (/home/user/public_html/node_modules/mysql/lib/protocol/Protocol.js:51:23)\n at Connection.connect (/home/user/public_html/node_modules/mysql/lib/Connection.js:116:18)\n at /home/user/public_html/node_modules/knex/lib/dialects/mysql/index.js:66:18\n at new Promise (<anonymous>)\n at Client_MySQL.acquireRawConnection (/home/user/public_html/node_modules/knex/lib/dialects/mysql/index.js:61:12)\n at create (/home/user/public_html/node_modules/knex/lib/client.js:262:39)\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)"

                }