I have my Node.js app working fine on Laravel Homestead, but now need to move it to the server. I'm using Laravel Forge for the server provisioning. The server already has Node and the required packages installed.
When running locally, I can just use Homestead's http://192.168.10.10:3000
to connect. What will the address be on my server, and how can I keep the node app running?
I can run it when I am connected via SSH, and I can see that it is outputting events received. But how do I connect the client to it? I have tried my server's IP and domain but no luck.
Once connected, how can I keep the node app running so I don't need to have an open SSH session?
Many thanks,
Sam
Install NodeJS if you don't have it already on the server:
sudo install nodejs
Push your app to whatever folder you want it.
Create an app (a site) for your NodeJS app on Laravel Forge.
At the bottom part, there will be a button to edit Nginx's configuration. If there exists a location / {
part, replace it with a reverse proxy (if there isn't, just add it):
location / {
proxy_pass http://SERVER_IP:APP_PORT;
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;
}
Restart nginx, run the app.
It should all be running as you want it to on the address you've provided Laravel Forge.
To set up restarting, you'll need to look into PM2. It's fairly straightforward.