I've done it before, and documented how, but it wont work, and I'm at my wits end. I cannot for the life of me deploy NestJs in NameCheap cPanel. And I know there are several other posts with small comments, but none of them are helpful.
I've regressed to creating a basic, bare bones nest project and trying to deploy it, but it wont work.
nest new basic-nest
with only the basic/root get endpoint that returns 'Hello World' from hitting the root endpoint(localhost:3000)I thought somewhere that perhaps another api is running on port 3000 thus why not working, so I added the possibility of environment variable...
Also tried enableCors for all because why not
! global enable CORS implemented]3
nest build
In cPanel, Setup Node.js App, configure as shown below, once created, stop the app to add package and dist files.
Now since creating the 'nest-basic' node application, going to the file manager, within the root home folder, the new folder 'nest-basic' was created. Within this folder I upload my package.json and create a dist folder, where i upload the dist files from 'nest build' from step 3.
Go back to cPanel -> Setup Node.js app -> edit 'nest-basic' app -> Run NPM Install(successful) -> Start App
7.Open the application url and nothing, everytime failure...
I'm not sure whats going wrong, Typescript compiled to JavaScript in the build, so its a NodeJs app, the build is executed through main.js in dist, and the package is installed in Namecheap NodeJS application setup, where I think the only dependency at this basic level that matters in production is @nestjs/core.
An alternate port is provided in environment variables but not necessary and CORS are enabled... One thing that I had previously added in another project was a.npmrc file which only included the text "scripts-prepend-node-path=true", however, adding it next to package.json in the file manager and/or building the app with the file included, same result, failure
I slept on it, after a week of brute force attempts, I slept on it...
The fix was to include the prefix in the root get request
Or really you should instead update main.ts with setGlobalPrefix as shown below instead of including the '/nest-basic' in all of the routes as shown above
Also, the .npmrc file in this basic setup was unnecessary, I believe it had something to do with assisting the connection to MongoDB in Nest in the past project where it was required.
Leaving this post as its a more thorough walkthrough than other cPanel NestJs posts...and I'm sure I'll go through this again in x months after not doing it for while