V
V
vitovt2017-06-07 11:32:40
Node.js
vitovt, 2017-06-07 11:32:40

How to run Nodejs in the background with Nginx?

Deploying a frontend written in React on a server that has other virtual hosts
The guys say you need to run a nodejs server.
From the point of view of Nginx settings, everything is clear -

location / {
                proxy_pass http://localhost:8080;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

For the node to work, they suggest going to the project folder and launching it
sudo npm run build
While the process is running - everything works, as soon as I exit the console - the server goes dead, that's it, Nginx returns 502
How can I run this node in the background, as a process, like nginx itself?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iBird Rose, 2017-06-07
@vitovt

sudo npm run build - builds a js file that you must include in the document. then the application will work without npm
, you need to debug the application through npm run start - then the application will only work when npm is running, but all changes made will immediately be displayed in live mode.

K
Konstantin Kitmanov, 2017-06-07
@k12th

If the frontend needs to be run using a nodejs server, and even under sudo, then something went very wrong :)
Try pm2 .
I have successfully used supervisord. They also say that in a distribution with systemd it is very easy to write the so-called. unit and it will run on startup and restart on crash.

O
Oleg Gamega, 2017-06-07
@gadfi

npm run build is to get a normal html + js bundle from a bunch of es6 / es7 flavored classes,
do npm run build in the project folder, the build butt will appear there, but with it, you can do it like with a regular html page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question