skip to Main Content

I am working on react js project & using node js for backend(to handle DB as well as to run CRON JOBs). At my local machine I had created 2 folders "botclient" & ‘botserver". I starts the server using "node server.js" in 1 command prompt & in another command prompt, I satrs client using "npm start". Now in browser I use "http://localhost:3000 & my application works.
Now my client has given me 1 shared hosted domain something like http://mybot.hismaindomain.in.
Now he has given me cPanel credentials to deploy this app. I have no idea how should I deploy it on server. I had tried lots of threads like "running nodejs react in one directory" or "react js nodejs deployment on hosted server" But I could not deploy the application on Hosted server.
I am total newbie in this technology so please help me to solve this problem. Whether I am doing wrong folder structure? Whether I need 2 sub domains?(for client and server separately)
Please help me. Thanks in advance.

2

Answers


  1. (This should be a comment but I csan’t comment yet)
    Maybe try using cPanel cron job to run the node command

    Login or Signup to reply.
  2. You do not need two sub-domains. Neither do you need a specific folder structure to have shared hosting.

    To run node two or more servers on the same host, from the same repository, from just one command line, you can use a package like ‘concurrently’ or ‘npm-run-all’, which lets one npm start-command activate a number of processes in parallell. For example: concurrently "node server.js --port 4000" "webpack --config client/webpack.config.js --port 3000" "node cron-jobs.js". In this example, the server is in the project root, and the react app is in client subfolder with its own package.json.

    Then, to share a domain it is necessary to setup a reverse proxy, so that the backend’s port can be accessed via a designated path, ie: /api. There are many ways to do it and there are others who would explain it better than me. Try google react node config reverse proxy or similar. Good to know is that the easiest solutions might be limited to a dev server, while the more complicated ones (like nginx) are independent on your tech stack (which you might not need).

    For cron jobs, you could try a package like ‘node-cron’, check this guide for the basics

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search