Install Node.js on OpenBSD 7.5
Step 1 – Install
pkg_add node
Step 2 – Verify
node --version && npm --version
Step 3 – Simple HTTP server
// app.js
const http = require('http');
http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello from Node.js!\n');
}).listen(3000, '127.0.0.1');
node app.js &
curl http://127.0.0.1:3000
Step 4 – systemd service
[Unit]
Description=My Node.js App
After=network.target
[Service]
User=nodejs
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node app.js
Restart=on-failure
Environment=NODE_ENV=production
[Install]
WantedBy=multi-user.target
Step 5 – Nginx reverse proxy
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
}