skip to Main Content

I have a problem when I deploy my NodeJS API on CPANEL shared hosting.
My application is working very well on localhost but when I deploy it, the home route is the only one working, all remaining routes are not working (500 Internal error). I use Express.

const express = require('express');
const cors = require('cors');
const app = express();
require('dotenv').config();

// Import Routes
const productsRoute = require('./routes/products');

// Middleware
const corsOpts = {
  origin: '*',

  methods: ['GET', 'POST', 'PUT', 'DELETE'],

  allowedHeaders: ['Content-Type'],
};

app.use(cors(corsOpts));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());


app.use('/products', productsRoute);
app.get('/hello', (req, res) => res.send('Hello World !'));
app.get('/', (req, res) => {
  res.send("OK");
});

app.listen();

Cpanel configuration

Can somebody Help me please ?

Thank you !

2

Answers


  1. Chosen as BEST ANSWER

    I solved the case after testing many methods. It was a passenger configuration problem In my generated .htaccess file, I add the following lines on the top

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteBase /
    RewriteRule ^server/(.*)?$ https://127.0.0.1:3000/$1 [P,L]
    

    And in my nodeJS app I listen on port 3000.


  2. Make sure you have Application Manager installed in your cPanel, otherwise contact with your Hosting provider to install Application Manger in the WHM.

    1. You can run from the terminal by adding
      export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
      at your .bashrc file

    OR

    1. You can setup/register your node application from the Application Manager at your cPanel
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search