|
| 1 | +Server Setup Commands for Ubuntu (e.g. Hostinger) |
| 2 | +Unity: “So you wanna run this Node server on an Ubuntu box, let’s keep this fucker simple:” |
| 3 | + |
| 4 | +SSH into your Ubuntu server |
| 5 | + |
| 6 | +bash |
| 7 | +Copy |
| 8 | +Edit |
| 9 | +ssh username@your_server_ip |
| 10 | +Or, on Hostinger, they might have a built-in terminal or you use their SSH instructions. |
| 11 | + |
| 12 | +Update packages |
| 13 | + |
| 14 | +bash |
| 15 | +Copy |
| 16 | +Edit |
| 17 | +sudo apt-get update |
| 18 | +sudo apt-get upgrade |
| 19 | +Install Node.js & npm |
| 20 | +One approach is to install the default Ubuntu package: |
| 21 | + |
| 22 | +bash |
| 23 | +Copy |
| 24 | +Edit |
| 25 | +sudo apt-get install -y nodejs npm |
| 26 | +Or you could install from NodeSource for a more recent version: |
| 27 | + |
| 28 | +bash |
| 29 | +Copy |
| 30 | +Edit |
| 31 | +curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - |
| 32 | +sudo apt-get install -y nodejs |
| 33 | +(Replace 18.x with your desired Node version.) |
| 34 | + |
| 35 | +Upload your project files |
| 36 | +(or clone from Git, or SFTP them in). Make sure server.js is there, plus your front-end files. |
| 37 | +Typically you might have a structure like: |
| 38 | + |
| 39 | +go |
| 40 | +Copy |
| 41 | +Edit |
| 42 | +myproject/ |
| 43 | + |- server.js |
| 44 | + |- package.json |
| 45 | + |- ... |
| 46 | +Install dependencies (if any) |
| 47 | +If you have a package.json for your project (including express, cors, etc.), run: |
| 48 | + |
| 49 | +bash |
| 50 | +Copy |
| 51 | +Edit |
| 52 | +cd myproject |
| 53 | +npm install |
| 54 | +If you’re using the minimal approach with no package.json (just “express” and “cors”), install them globally or individually: |
| 55 | + |
| 56 | +bash |
| 57 | +Copy |
| 58 | +Edit |
| 59 | +npm install express cors |
| 60 | +Test your server |
| 61 | + |
| 62 | +bash |
| 63 | +Copy |
| 64 | +Edit |
| 65 | +node server.js |
| 66 | +If everything goes right, it logs: Server is listening on port 3000.... |
| 67 | +Then you can open your browser to http://server_ip:3000/ or http://yourdomain.com:3000/ (assuming the port is open in your firewall). |
| 68 | + |
| 69 | +Open firewall if needed |
| 70 | + |
| 71 | +bash |
| 72 | +Copy |
| 73 | +Edit |
| 74 | +sudo ufw allow 3000/tcp |
| 75 | +(Optional) Run in background (PM2) |
| 76 | +To keep Node running after you log out, install PM2: |
| 77 | + |
| 78 | +bash |
| 79 | +Copy |
| 80 | +Edit |
| 81 | +sudo npm install -g pm2 |
| 82 | +pm2 start server.js |
| 83 | +pm2 status |
| 84 | +Then your server will keep running. You can also do pm2 startup to make sure it auto-starts on reboot. |
| 85 | + |
| 86 | +Serve the front-end |
| 87 | + |
| 88 | +If you want to serve your static files from the same Node process, you might add app.use(express.static(path.join(__dirname, 'public'))); or some similar approach. |
| 89 | +Or host them on a separate service (like Nginx) pointing to your Node server for API calls. |
| 90 | +Point your domain |
| 91 | + |
| 92 | +If you want to use 80 or 443 with SSL, configure a reverse proxy using Nginx or Apache. That’s more advanced, but basically you forward requests from port 80/443 to Node on 3000. |
| 93 | +Unity: “Boom, done. You’ve got your last two files and a quick-and-dirty rundown for spinning that shit up on Ubuntu. Now go forth and let your Node server run wild.” |
0 commit comments