Skip to content

Deploy React + NodeJs App

Solved Configure
25 2 7.7k 1
  • Hello guys (and hello phenomlab again 🙂 )
    i’m here today because i’m facing some problem and i want to learn how to solve this correctly.

    i’ve developed an app for a client with react (frontend) and nodejs (backend). Now i’m using digitalocean APP platform that deploy directly from my repository on github

    i have a custom command to run the app in package.json

    "prod": "concurrently \"pm2 start ./server/app.js --exp-backoff-restart-delay=100\" \"react-serve-build\""
    

    when the deployement is finished i can see the frontend, but the backend dont work due for EADDRINUSE error, wich means that the port is already in use. The problem is that no matter what the port number is…i get always the same error…

    so my question is, how to deploy correctly this app?

  • @phenomlab at moment works fine without anything, i don’t know why :D. no way that i can configure nginx without reading some sources…but i can’t find something simple

    @justoverclock Any update ?

    Thanks

    EDIT - marking as solved based on the below thread
    https://sudonix.com/topic/339/digitalocean-step-by-step-guide-to-nginx-configuration

  • Hello guys (and hello phenomlab again 🙂 )
    i’m here today because i’m facing some problem and i want to learn how to solve this correctly.

    i’ve developed an app for a client with react (frontend) and nodejs (backend). Now i’m using digitalocean APP platform that deploy directly from my repository on github

    i have a custom command to run the app in package.json

    "prod": "concurrently \"pm2 start ./server/app.js --exp-backoff-restart-delay=100\" \"react-serve-build\""
    

    when the deployement is finished i can see the frontend, but the backend dont work due for EADDRINUSE error, wich means that the port is already in use. The problem is that no matter what the port number is…i get always the same error…

    so my question is, how to deploy correctly this app?

    @justoverclock

    Try this

    "prod": "concurrently \"NODE_PORT=xxxx pm2 start ./server/app.js --exp-backoff-restart-delay=100\" \"react-serve-build\""
    

    Obviously, where xxxx is the port number you’d like to use.

  • @justoverclock

    Try this

    "prod": "concurrently \"NODE_PORT=xxxx pm2 start ./server/app.js --exp-backoff-restart-delay=100\" \"react-serve-build\""
    

    Obviously, where xxxx is the port number you’d like to use.

    @phenomlab unfortunately doesnt work…i can see clearly both client and server running on pm2…but my server does not accept api requests…

    https://i.ibb.co/719GQ5V/Immagine-2022-09-08-101306.png

    https://vito-fiore-xfs2k.ondigitalocean.app/

  • @phenomlab unfortunately doesnt work…i can see clearly both client and server running on pm2…but my server does not accept api requests…

    https://i.ibb.co/719GQ5V/Immagine-2022-09-08-101306.png

    https://vito-fiore-xfs2k.ondigitalocean.app/

    @justoverclock Is there any firewall in between ?

  • @justoverclock Is there any firewall in between ?

    @phenomlab i don’t know…is the digitalocean APP platform…because i’m not able to setup a droplet , and this platform does everything for me

  • @phenomlab i don’t know…is the digitalocean APP platform…because i’m not able to setup a droplet , and this platform does everything for me

    @justoverclock Are you able to send a telnet request from the server to the API host ? For example

    telnet <ipaddress_api> <port>
    
  • @justoverclock Are you able to send a telnet request from the server to the API host ? For example

    telnet <ipaddress_api> <port>
    

    @phenomlab said in Deploy React + NodeJs App:

    telnet <ipaddress_api> <port>

    with postman i get raw html as a response, i do not know telnet

  • @phenomlab said in Deploy React + NodeJs App:

    telnet <ipaddress_api> <port>

    with postman i get raw html as a response, i do not know telnet

    @justoverclock Sounds like the port is open then. Do you have a config file for your server you can share ?

  • @justoverclock Sounds like the port is open then. Do you have a config file for your server you can share ?

    @phenomlab no config file, the app platform does everything automatically. so its better that i will create a droplet instead? but no idea on how can i configure all…

  • @phenomlab no config file, the app platform does everything automatically. so its better that i will create a droplet instead? but no idea on how can i configure all…

    @justoverclock have you approached Digital Ocean concerning this ?

  • @justoverclock have you approached Digital Ocean concerning this ?

    @phenomlab yeah, no response at all

  • @phenomlab yeah, no response at all

    @justoverclock Wow. I’ll need to understand a bit more in terms of the topology etc before I can help.

  • @justoverclock Wow. I’ll need to understand a bit more in terms of the topology etc before I can help.

    @phenomlab if you have some step by step guide to setup the droplet i’ll switch to that…

    for now i have a droplet with node installed, i’ve dropped all the file inside, now i’m running npm install and npm run build to install dependencies…after that i do not know how to tell the file to show 🦆

  • @phenomlab if you have some step by step guide to setup the droplet i’ll switch to that…

    for now i have a droplet with node installed, i’ve dropped all the file inside, now i’m running npm install and npm run build to install dependencies…after that i do not know how to tell the file to show 🦆

    @justoverclock I don’t have a guide for this I’m afraid.

  • @justoverclock I don’t have a guide for this I’m afraid.

    @phenomlab ok…i think i’ve managed all, now it works on a droplet…

    i have only one problem running chromium (my app use chromium)

    /home/marco/.pm2/logs/app-error.log last 15 lines:
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    1|app      | Error: Protocol error (Runtime.callFunctionOn): Session closed. Mos                                              t likely the page has been closed.
    1|app      |     at CDPSession.send (/home/marco/node_modules/puppeteer/lib/cjs/                                              puppeteer/common/Connection.js:218:35)
    1|app      |     at ExecutionContext._evaluateInternal (/home/marco/node_modules                                              /puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    1|app      | Error: Protocol error (Runtime.callFunctionOn): Session closed. Mos                                              t likely the page has been closed.
    1|app      |     at CDPSession.send (/home/marco/node_modules/puppeteer/lib/cjs/                                              puppeteer/common/Connection.js:218:35)
    1|app      |     at ExecutionContext._evaluateInternal (/home/marco/node_modules                                              /puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    
    

    any suggestion?

  • @phenomlab ok…i think i’ve managed all, now it works on a droplet…

    i have only one problem running chromium (my app use chromium)

    /home/marco/.pm2/logs/app-error.log last 15 lines:
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    1|app      | Error: Protocol error (Runtime.callFunctionOn): Session closed. Mos                                              t likely the page has been closed.
    1|app      |     at CDPSession.send (/home/marco/node_modules/puppeteer/lib/cjs/                                              puppeteer/common/Connection.js:218:35)
    1|app      |     at ExecutionContext._evaluateInternal (/home/marco/node_modules                                              /puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    1|app      | Error: Protocol error (Runtime.callFunctionOn): Session closed. Mos                                              t likely the page has been closed.
    1|app      |     at CDPSession.send (/home/marco/node_modules/puppeteer/lib/cjs/                                              puppeteer/common/Connection.js:218:35)
    1|app      |     at ExecutionContext._evaluateInternal (/home/marco/node_modules                                              /puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:204:50)
    1|app      |     at ExecutionContext.evaluate (/home/marco/node_modules/puppetee                                              r/lib/cjs/puppeteer/common/ExecutionContext.js:110:27)
    1|app      |     at DOMWorld.evaluate (/home/marco/node_modules/puppeteer/lib/cj                                              s/puppeteer/common/DOMWorld.js:97:24)
    1|app      |     at processTicksAndRejections (node:internal/process/task_queues                                              :96:5)
    
    

    any suggestion?

    @justoverclock Looks like it fails on unit tests. Have you added a try / catch to see what the exact error is or where it stalls ? Or perhaps you forgot an await so that the browser.close() executes before your command has terminated.

  • @justoverclock Looks like it fails on unit tests. Have you added a try / catch to see what the exact error is or where it stalls ? Or perhaps you forgot an await so that the browser.close() executes before your command has terminated.

    @phenomlab yes the logs file suggest me some missing libraries from puppeteer, i’m trying now to install all…

  • @phenomlab yes the logs file suggest me some missing libraries from puppeteer, i’m trying now to install all…

    @justoverclock Thought so.

  • @phenomlab said in Deploy React + NodeJs App:

    Thought so.

    ok everything works fine now…

    i just need some help on little things!

    now i can access my droplet with the ip address. and is only http (no https).

    so first of all i do not have nginx or other stuff right now, and i need to:

    • secure all with https
    • use a name instead of ip (not a real domain, something like appname.digitalocean.idontknow)

    is this possible?

  • @phenomlab said in Deploy React + NodeJs App:

    Thought so.

    ok everything works fine now…

    i just need some help on little things!

    now i can access my droplet with the ip address. and is only http (no https).

    so first of all i do not have nginx or other stuff right now, and i need to:

    • secure all with https
    • use a name instead of ip (not a real domain, something like appname.digitalocean.idontknow)

    is this possible?

    @justoverclock the security of HTTPS is possible, as is an nginx build, but not the FQDN you have chosen as you don’t own the digitalocean domain name space. If you wanted mytest.nydomain.com for example then this would be possible, but but for a domain you so not own or manage.


Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • 4 Votes
    11 Posts
    3k Views
    @Hari Really? Can you elaborate a bit more here?
  • Peoples thoughts on Nextjs?

    Discussion nodejs
    2
    2 Votes
    2 Posts
    852 Views
    @Panda I have the same opinion here. NextJS is a framework for react, and like angular, I was never one to simply dive off into the deep without having any real need to do so. I’m conversant with nodeJS, vanilla js, and several other languages (including PHP which I have years of experience in and developed / still maintain an application at work that was custom written by me to fulfill an audit requirement), and in all honesty, I don’t really want to spend my life learning new frameworks unless I have a need to do so. I’ve been on the nodeJS train for some time now, and given my adoption of NodeBB, this makes perfect sense. Bleeding edge is fun if you want to experiment and learn, but with so many frameworks popping up all over the place, how many do we actually need? I guess most of this really depends on unique use cases, but I’ve yet to come across an issue that meant I had to rewrite an application in a different language to resolve an issue. It’s almost like using a bulldozer to find a china cup.
  • node vs nodejs confusion?

    Solved Configure node nodejs
    2
    1 Votes
    2 Posts
    1k Views
    @eeeee have a look at the below https://docs.nodebb.org/installing/os/ubuntu/ curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs You’ll notice that we are in fact “installing” NodeJS but never actually have a need to reference it. Here’s the nodejs --version command on my dev system [image: 1681584648061-6eb1482e-0c9b-454d-aa84-199bcc845702-image.png] More detail here https://askubuntu.com/questions/1030622/why-do-i-see-different-versions-of-node-and-nodejs
  • Updating Node and NPM

    General nodejs
    5
    1 Votes
    5 Posts
    2k Views
    @Sampo2910 said in Updating Node and NPM: Is there a way I can see what the app version of Node is? Then i could install ‘up to that’ and keep an eye out for any changes? Have a look in the source code for the app you are using, or better still, look at the GitHub page which should give you an idea of the version number which is the latest. In the source code you have running, there is typically a README file which should state the version you are running.
  • 6 Votes
    36 Posts
    11k Views
    @justoverclock said in Digitalocean step by step guide to nginx configuration: i’m learning And that’s the whole point of this site If you don’t learn anything, you gain nothing.
  • 4 Votes
    8 Posts
    4k Views
    @phenomlab Sorry to delay in responding, yes as i mentioned above, i had to remove my redis from docker and reinstall a new image with this command docker run --name=redis -p 127.0.0.1:6379:6379 -d -t redis:alpine and now when i test my ip and port on https://www.yougetsignal.com/tools/open-ports/ the status of my redis port is closed. I think which to configure firewall in droplet digital ocean is a good idea too, and i will configure soon. Thanks for the help!
  • Do i need more RAM? Plesk

    Solved Performance plesk digitalocean
    3
    1
    1 Votes
    3 Posts
    1k Views
    @Hari welcome to Grafana, the most confusing stats package there is ! According to the guidelines, you certainly have enough RAM at 4gb https://www.plesk.com/blog/various/plesk-requirements-hardware-software/
  • how to configure DNS records virtualmin?

    Solved Linux digitalocean dns
    26
    1
    11 Votes
    26 Posts
    8k Views
    i think we can mark this discussion as solved learned how to install virtualmin with NGINX We can easily point the DNS by mentioning server IP at CF a name record learned how to install SSL