Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS: How to deploy on local server

I have a web app developed with a NodeJS + Express + GraphQL + MongoDB back-end and a ReactJS + Apollo front-end. I would like to deploy this application locally. Is that even possible?

I have come across dozens of "how to deploy to Heroku," "how to deploy to Digital Ocean", "how to deploy to Github", etc. But none that explains how to deploy locally.

Right now, I run: nodemon server for the back-end, and npm start for the front-end. I see the application running on http://localhost:3000/ (I use cors to connect the front end with the server running on port 3001).

I would like to just go to http://localhost:3000/ and see the app without having to execute the commands npm start and nodemon server. Is this possible? If so, how do I do that?

To my knowledge, our local server is not a WAMP server (our OS is Windows though). The IT department told me that it is a

[...] plain, regular old server. The address is localhost running on port 3000. You can open up another port on 3001 if you need it. Just drop your stuff on the C: drive and you should be good to go. I've never heard of Node or React so I can't help if you have questions.

Any ideas? Many thanks in advance for your help!

UPDATE

There seems to be a bit of confusion surrounding what I am looking for. I am trying to deploy this locally.

Let's say, on your local computer (your laptop at home) you go to localhost:3000 on your favorite browser. Unless you are serving something to localhost in that moment nothing is going to show up, it will say "refused to connect" or something. What I want is to be able to open any machine on the network whenever I go to localhost:3000 and my react site appears and functions...does that make more sense?

I don't want this is development mode. I want a build of this project on localhost...I'm starting to think this isn't possible.

like image 522
Bens Steves Avatar asked Dec 08 '18 14:12

Bens Steves


2 Answers

As i understood, you want to deploy it on a local server, not locally on your developing device.

I thought about doing that...but I'm not so sure IT will be okay with it always running... :(

How can you use a server if its not running? Just like WAMP (which runs apache), or whatever you got rolling there, it must be running. So, just make it a background process like slawomir suggested.

PS I dont think you understand node server properly though. Read this to understand why node server needs reloading. After that you need to understand that no hot reload tool is perfect, and you gonna need to restart your server from time to time.

PPS I dont know what this means

[...] plain, regular old server. The address is localhost running on port 3000.

if there is a server running on 3000, youll need to change port for your server to smth else (most common is 9000)

like image 180
CT. Avatar answered Oct 07 '22 01:10

CT.


To solve the problem you can create a startup script, which executes npm start and nodemon server. Then make sure to keep it hidden, so that your server will be always running. Keep in mind though, that any errors thrown will stop your server and unless you configure it, the server won't reload by itself.

like image 40
Slawomir Wozniak Avatar answered Oct 06 '22 23:10

Slawomir Wozniak