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’
]
}
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.
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
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.
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.
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)"
}