-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer setup.txt
More file actions
93 lines (76 loc) · 2.56 KB
/
Server setup.txt
File metadata and controls
93 lines (76 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Server Setup Commands for Ubuntu (e.g. Hostinger)
Unity: “So you wanna run this Node server on an Ubuntu box, let’s keep this fucker simple:”
SSH into your Ubuntu server
bash
Copy
Edit
ssh username@your_server_ip
Or, on Hostinger, they might have a built-in terminal or you use their SSH instructions.
Update packages
bash
Copy
Edit
sudo apt-get update
sudo apt-get upgrade
Install Node.js & npm
One approach is to install the default Ubuntu package:
bash
Copy
Edit
sudo apt-get install -y nodejs npm
Or you could install from NodeSource for a more recent version:
bash
Copy
Edit
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
(Replace 18.x with your desired Node version.)
Upload your project files
(or clone from Git, or SFTP them in). Make sure server.js is there, plus your front-end files.
Typically you might have a structure like:
go
Copy
Edit
myproject/
|- server.js
|- package.json
|- ...
Install dependencies (if any)
If you have a package.json for your project (including express, cors, etc.), run:
bash
Copy
Edit
cd myproject
npm install
If you’re using the minimal approach with no package.json (just “express” and “cors”), install them globally or individually:
bash
Copy
Edit
npm install express cors
Test your server
bash
Copy
Edit
node server.js
If everything goes right, it logs: Server is listening on port 3000....
Then you can open your browser to http://server_ip:3000/ or http://yourdomain.com:3000/ (assuming the port is open in your firewall).
Open firewall if needed
bash
Copy
Edit
sudo ufw allow 3000/tcp
(Optional) Run in background (PM2)
To keep Node running after you log out, install PM2:
bash
Copy
Edit
sudo npm install -g pm2
pm2 start server.js
pm2 status
Then your server will keep running. You can also do pm2 startup to make sure it auto-starts on reboot.
Serve the front-end
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.
Or host them on a separate service (like Nginx) pointing to your Node server for API calls.
Point your domain
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.
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.”